Teaches l1_walk_sessions a new session_kind='ai_build' for AI-generated decision-tree walks. FK shape matches adhoc: both flow_id and flow_proposal_id must be NULL. Drops and recreates the two affected CHECK constraints (session_kind allowlist + target_consistency). Migration beca7464b6b4 chains from b3358ba0e48c. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""add ai_build session kind
|
|
|
|
Revision ID: beca7464b6b4
|
|
Revises: b3358ba0e48c
|
|
Create Date: 2026-05-29 18:41:38.601537
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'beca7464b6b4'
|
|
down_revision: Union[str, None] = 'b3358ba0e48c'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.drop_constraint("ck_l1_walk_sessions_session_kind", "l1_walk_sessions", type_="check")
|
|
op.create_check_constraint(
|
|
"ck_l1_walk_sessions_session_kind", "l1_walk_sessions",
|
|
"session_kind IN ('flow', 'proposal', 'adhoc', 'ai_build')",
|
|
)
|
|
op.drop_constraint("ck_l1_walk_sessions_target_consistency", "l1_walk_sessions", type_="check")
|
|
op.create_check_constraint(
|
|
"ck_l1_walk_sessions_target_consistency", "l1_walk_sessions",
|
|
"(session_kind = 'flow' AND flow_id IS NOT NULL AND flow_proposal_id IS NULL) "
|
|
"OR (session_kind = 'proposal' AND flow_proposal_id IS NOT NULL AND flow_id IS NULL) "
|
|
"OR (session_kind IN ('adhoc', 'ai_build') AND flow_id IS NULL AND flow_proposal_id IS NULL)",
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_constraint("ck_l1_walk_sessions_target_consistency", "l1_walk_sessions", type_="check")
|
|
op.create_check_constraint(
|
|
"ck_l1_walk_sessions_target_consistency", "l1_walk_sessions",
|
|
"(session_kind = 'flow' AND flow_id IS NOT NULL AND flow_proposal_id IS NULL) "
|
|
"OR (session_kind = 'proposal' AND flow_proposal_id IS NOT NULL AND flow_id IS NULL) "
|
|
"OR (session_kind = 'adhoc' AND flow_id IS NULL AND flow_proposal_id IS NULL)",
|
|
)
|
|
op.drop_constraint("ck_l1_walk_sessions_session_kind", "l1_walk_sessions", type_="check")
|
|
op.create_check_constraint(
|
|
"ck_l1_walk_sessions_session_kind", "l1_walk_sessions",
|
|
"session_kind IN ('flow', 'proposal', 'adhoc')",
|
|
)
|