"""generate execution_transitions
Revision ID: 6a4d4dc3d8dc
Revises: f71305fb69b9
Create Date: 2025-12-22 14:34:50.860339
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6a4d4dc3d8dc'
down_revision: Union[str, Sequence[str], None] = 'f71305fb69b9'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('execution_transitions',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('organization_id', sa.String(), nullable=False),
    sa.Column('execution_id', sa.UUID(), nullable=False),
    sa.Column('turn_number', sa.Integer(), nullable=False),
    sa.Column('from_state', sa.String(length=50), nullable=False),
    sa.Column('to_state', sa.String(length=50), nullable=False),
    sa.Column('reasoning', sa.String(), nullable=False),
    sa.Column('confidence', sa.String(length=20), nullable=False),
    sa.Column('decision_factors', sa.JSON(), nullable=True),
    sa.Column('ai_model', sa.String(length=100), nullable=True),
    sa.Column('decision_time_ms', sa.Integer(), nullable=True),
    sa.Column('is_manual_override', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['execution_id'], ['executions.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_execution_transitions_execution_id'), 'execution_transitions', ['execution_id'], unique=False)
    op.create_index(op.f('ix_execution_transitions_organization_id'), 'execution_transitions', ['organization_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_execution_transitions_organization_id'), table_name='execution_transitions')
    op.drop_index(op.f('ix_execution_transitions_execution_id'), table_name='execution_transitions')
    op.drop_table('execution_transitions')
    # ### end Alembic commands ###