Skip to content

Commit

Permalink
Replace null artefact status with 'UNDECIDED'
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Dec 4, 2023
1 parent 7300799 commit 3afdd6b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Make artefact status not nullable
Revision ID: 8317277d4333
Revises: 8d8643821588
Create Date: 2023-12-04 08:20:23.131927+00:00
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "8317277d4333"
down_revision = "8d8643821588"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.execute("ALTER TYPE artefact_status_enum RENAME TO artefact_status_enum_old")
op.execute(
"CREATE TYPE artefact_status_enum AS "
"ENUM('APPROVED', 'MARKED_AS_FAILED', 'UNDECIDED')"
)
op.execute(
"ALTER TABLE artefact ALTER COLUMN status TYPE "
"artefact_status_enum USING status::text::artefact_status_enum"
)
op.execute("DROP TYPE artefact_status_enum_old")
op.execute("UPDATE artefact SET status = 'UNDECIDED' WHERE status IS NULL")
op.execute("ALTER TABLE artefact ALTER COLUMN status SET NOT NULL")


def downgrade() -> None:
op.execute("ALTER TYPE artefact_status_enum RENAME TO artefact_status_enum_old")
op.execute(
"CREATE TYPE artefact_status_enum AS ENUM('APPROVED', 'MARKED_AS_FAILED')"
)
op.execute("ALTER TABLE artefact ALTER COLUMN status SET NULL")
op.execute("UPDATE artefact SET status = NULL WHERE status = 'UNDECIDED'")
op.execute(
"ALTER TABLE artefact ALTER COLUMN status TYPE "
"artefact_status_enum USING status::text::artefact_status_enum"
)
op.execute("DROP TYPE artefact_status_enum_old")
2 changes: 1 addition & 1 deletion backend/test_observer/data_access/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Artefact(Base):
)
# Default fields
due_date: Mapped[date | None]
status: Mapped[ArtefactStatus | None]
status: Mapped[ArtefactStatus]

__table_args__ = (
UniqueConstraint("name", "version", "track", name="unique_snap"),
Expand Down
1 change: 1 addition & 0 deletions backend/test_observer/data_access/models_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ class TestExecutionStatus(Enum):
class ArtefactStatus(str, Enum):
APPROVED = "APPROVED"
MARKED_AS_FAILED = "MARKED_AS_FAILED"
UNDECIDED = "UNDECIDED"

0 comments on commit 3afdd6b

Please sign in to comment.