"""add intent_steps for state machine (Спринт 6a) Revision ID: a4c82f1b9e33 Revises: 3f1d9a5b7c42 Create Date: 2026-04-24 18:30:00.000000 Таблица шагов state machine внутри ветки. `allowed_next` — JSON-список кодов шагов, в которые разрешён переход. `guards` — JSON-словарь с условиями блокировки (наполняется в Спринте 6b). """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa revision: str = 'a4c82f1b9e33' down_revision: Union[str, None] = '3f1d9a5b7c42' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.create_table( 'intent_steps', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('intent_id', sa.Integer(), nullable=False), sa.Column('code', sa.String(length=50), nullable=False), sa.Column('name', sa.String(length=200), nullable=False), sa.Column('order_index', sa.Integer(), nullable=False, server_default='0'), sa.Column('system_prompt', sa.Text(), nullable=False, server_default=''), sa.Column('allowed_next_json', sa.Text(), nullable=False, server_default='[]'), sa.Column('guards_json', sa.Text(), nullable=False, server_default='{}'), sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False), sa.ForeignKeyConstraint( ['intent_id'], ['intents.id'], name='fk_intent_steps_intent_id', ondelete='CASCADE', ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('intent_id', 'code', name='uq_intent_step_code'), ) op.create_index('ix_intent_steps_intent_id', 'intent_steps', ['intent_id'], unique=False) def downgrade() -> None: op.drop_index('ix_intent_steps_intent_id', table_name='intent_steps') op.drop_table('intent_steps')