From 969a1b59054ca01f6f20b91a5517879e34266080 Mon Sep 17 00:00:00 2001 From: Artem Kashaev Date: Thu, 27 Nov 2025 16:07:55 +0500 Subject: [PATCH] feat: add migration to include 'stage_changed' activity type --- ...251127_0002_stage_changed_activity_enum.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 migrations/versions/20251127_0002_stage_changed_activity_enum.py 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;")