"""add llm generation detail table.

Revision ID: 85c8b4a64f53
Revises: 7bb281b7a422
Create Date: 2025-12-10 16:17:46.597669

"""
from alembic import op
import models as models
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '85c8b4a64f53'
down_revision = 'aab323465866'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('llm_generation_details',
    sa.Column('id', models.types.StringUUID(), nullable=False),
    sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
    sa.Column('app_id', models.types.StringUUID(), nullable=False),
    sa.Column('message_id', models.types.StringUUID(), nullable=True),
    sa.Column('workflow_run_id', models.types.StringUUID(), nullable=True),
    sa.Column('node_id', sa.String(length=255), nullable=True),
    sa.Column('reasoning_content', models.types.LongText(), nullable=True),
    sa.Column('tool_calls', models.types.LongText(), nullable=True),
    sa.Column('sequence', models.types.LongText(), nullable=True),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
    sa.CheckConstraint('(message_id IS NOT NULL AND workflow_run_id IS NULL AND node_id IS NULL) OR (message_id IS NULL AND workflow_run_id IS NOT NULL AND node_id IS NOT NULL)', name=op.f('llm_generation_details_ck_llm_generation_detail_assoc_mode_check')),
    sa.PrimaryKeyConstraint('id', name='llm_generation_detail_pkey'),
    sa.UniqueConstraint('message_id', name=op.f('llm_generation_details_message_id_key'))
    )
    with op.batch_alter_table('llm_generation_details', schema=None) as batch_op:
        batch_op.create_index('idx_llm_generation_detail_message', ['message_id'], unique=False)
        batch_op.create_index('idx_llm_generation_detail_workflow', ['workflow_run_id', 'node_id'], unique=False)



def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('llm_generation_details')
    # ### end Alembic commands ###
