-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend Bodhi and pipeline API (#2311)
Extend Bodhi and pipeline API Extend Bodhi API with info about times and pipelines API with info about Bodhi updates. RELEASE NOTES BEGIN N/A RELEASE NOTES END Reviewed-by: Matej Focko
- Loading branch information
Showing
9 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
alembic/versions/a3a17014c282_add_times_for_bodhi_update_targets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
"""Add times for Bodhi update targets | ||
Revision ID: a3a17014c282 | ||
Revises: 8ba13238bfa4 | ||
Create Date: 2024-01-20 22:05:46.749382 | ||
""" | ||
from datetime import datetime | ||
from typing import TYPE_CHECKING | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy import orm, Column, Integer, String, JSON, DateTime, ForeignKey | ||
from sqlalchemy.orm import relationship, declarative_base | ||
|
||
from packit_service.models import ( | ||
GroupAndTargetModelConnector, | ||
ProjectAndEventsConnector, | ||
GroupModel, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a3a17014c282" | ||
down_revision = "8ba13238bfa4" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
if TYPE_CHECKING: | ||
Base = object | ||
else: | ||
Base = declarative_base() | ||
|
||
|
||
class PipelineModel(Base): | ||
""" | ||
Represents one pipeline. | ||
Connects ProjectEventModel (and project events like PullRequestModel via that model) with | ||
build/test models like SRPMBuildModel, CoprBuildTargetModel, KojiBuildTargetModel, | ||
and TFTTestRunGroupModel. | ||
* One model of each build/test target/group model can be connected. | ||
* Each build/test model can be connected to multiple PipelineModels (e.g. on retrigger). | ||
* Each PipelineModel has to be connected to exactly one ProjectEventModel. | ||
* There can be multiple PipelineModels for one ProjectEventModel. | ||
(e.g. For each push to PR, there will be new PipelineModel, but same ProjectEventModel.) | ||
""" | ||
|
||
__tablename__ = "pipelines" | ||
id = Column(Integer, primary_key=True) # our database PK | ||
datetime = Column(DateTime, default=datetime.utcnow) | ||
bodhi_update_group_id = Column( | ||
Integer, ForeignKey("bodhi_update_groups.id"), index=True | ||
) | ||
bodhi_update_group = relationship("BodhiUpdateGroupModel", back_populates="runs") | ||
|
||
|
||
class BodhiUpdateGroupModel(ProjectAndEventsConnector, GroupModel, Base): | ||
__tablename__ = "bodhi_update_groups" | ||
id = Column(Integer, primary_key=True) | ||
submitted_time = Column(DateTime, default=datetime.utcnow) | ||
|
||
runs = relationship("PipelineModel", back_populates="bodhi_update_group") | ||
bodhi_update_targets = relationship( | ||
"BodhiUpdateTargetModel", back_populates="group_of_targets" | ||
) | ||
|
||
|
||
class BodhiUpdateTargetModel(GroupAndTargetModelConnector, Base): | ||
__tablename__ = "bodhi_update_targets" | ||
id = Column(Integer, primary_key=True) | ||
status = Column(String) | ||
target = Column(String) | ||
web_url = Column(String) | ||
koji_nvr = Column(String) | ||
alias = Column(String) | ||
submitted_time = Column(DateTime, default=datetime.utcnow) | ||
update_creation_time = Column(DateTime) | ||
data = Column(JSON) | ||
bodhi_update_group_id = Column(Integer, ForeignKey("bodhi_update_groups.id")) | ||
|
||
group_of_targets = relationship( | ||
"BodhiUpdateGroupModel", back_populates="bodhi_update_targets" | ||
) | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"bodhi_update_targets", | ||
sa.Column("submitted_time", sa.DateTime(), nullable=True), | ||
) | ||
op.add_column( | ||
"bodhi_update_targets", | ||
sa.Column("update_creation_time", sa.DateTime(), nullable=True), | ||
) | ||
|
||
bind = op.get_bind() | ||
session = orm.Session(bind=bind) | ||
|
||
for bodhi_update in session.query(BodhiUpdateTargetModel).all(): | ||
bodhi_update.submitted_time = bodhi_update.group_of_targets.submitted_time | ||
session.add(bodhi_update) | ||
|
||
session.commit() | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("bodhi_update_targets", "update_creation_time") | ||
op.drop_column("bodhi_update_targets", "submitted_time") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters