mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
feat(automations): migrate automation_trigger_type enum to add event
This commit is contained in:
parent
9247a2337f
commit
356400ae2a
1 changed files with 47 additions and 0 deletions
|
|
@ -0,0 +1,47 @@
|
|||
"""Add 'event' to automation_trigger_type enum
|
||||
|
||||
Revision ID: 147
|
||||
Revises: 146
|
||||
Create Date: 2026-05-29
|
||||
|
||||
Adds the ``event`` value to the ``automation_trigger_type`` enum so automations
|
||||
can be triggered by published domain events, alongside the existing
|
||||
``schedule`` triggers.
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "147"
|
||||
down_revision: str | None = "146"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
ENUM_NAME = "automation_trigger_type"
|
||||
NEW_VALUE = "event"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Safely add 'event' to automation_trigger_type enum if missing."""
|
||||
op.execute(
|
||||
f"""
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_type t
|
||||
JOIN pg_enum e ON t.oid = e.enumtypid
|
||||
WHERE t.typname = '{ENUM_NAME}' AND e.enumlabel = '{NEW_VALUE}'
|
||||
) THEN
|
||||
ALTER TYPE {ENUM_NAME} ADD VALUE '{NEW_VALUE}';
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""No-op: PostgreSQL does not support removing enum values."""
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue