diff --git a/migrations/versions/20251127_0002_stage_changed_activity_enum.py b/migrations/versions/20251127_0002_stage_changed_activity_enum.py new file mode 100644 index 0000000..c5e0115 --- /dev/null +++ b/migrations/versions/20251127_0002_stage_changed_activity_enum.py @@ -0,0 +1,26 @@ +"""Add stage_changed activity type.""" +from __future__ import annotations + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "20251127_0002_stage_changed" +down_revision: str | None = "20251122_0001" +branch_labels: tuple[str, ...] | None = None +depends_on: tuple[str, ...] | None = None + + +def upgrade() -> None: + op.execute("ALTER TYPE activity_type ADD VALUE IF NOT EXISTS 'stage_changed';") + + +def downgrade() -> None: + op.execute("UPDATE activities SET type = 'status_changed' WHERE type = 'stage_changed';") + op.execute("ALTER TYPE activity_type RENAME TO activity_type_old;") + op.execute( + "CREATE TYPE activity_type AS ENUM ('comment','status_changed','task_created','system');" + ) + op.execute( + "ALTER TABLE activities ALTER COLUMN type TYPE activity_type USING type::text::activity_type;" + ) + op.execute("DROP TYPE activity_type_old;")