"""202512171846

Revision ID: 87a6537b4074
Revises: 64ddbf3c3bcc
Create Date: 2025-12-17 18:45:16.574812

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '87a6537b4074'
down_revision: Union[str, None] = '64ddbf3c3bcc'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('prompt_model_config',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('tenant_id', sa.UUID(), nullable=False, comment='Tenant ID'),
    sa.Column('system_prompt', sa.Text(), nullable=False, comment='System Prompt'),
    sa.Column('created_at', sa.DateTime(), nullable=True, comment='Creation Time'),
    sa.Column('updated_at', sa.DateTime(), nullable=True, comment='Update Time'),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_prompt_model_config_id'), 'prompt_model_config', ['id'], unique=False)
    op.create_table('prompt_opt_session_list',
    sa.Column('id', sa.UUID(), nullable=False, comment='Session ID'),
    sa.Column('tenant_id', sa.UUID(), nullable=False, comment='Tenant ID'),
    sa.Column('user_id', sa.UUID(), nullable=False, comment='User ID'),
    sa.Column('created_at', sa.DateTime(), nullable=True, comment='Creation Time'),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_prompt_opt_session_list_created_at'), 'prompt_opt_session_list', ['created_at'], unique=False)
    op.create_index(op.f('ix_prompt_opt_session_list_id'), 'prompt_opt_session_list', ['id'], unique=False)
    op.create_table('prompt_opt_session_history',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('tenant_id', sa.UUID(), nullable=False, comment='Tenant ID'),
    sa.Column('session_id', sa.UUID(), nullable=False, comment='Session ID'),
    sa.Column('user_id', sa.UUID(), nullable=False, comment='User ID'),
    sa.Column('role', sa.String(), nullable=False, comment='Message Role'),
    sa.Column('content', sa.Text(), nullable=False, comment='Message Content'),
    sa.Column('created_at', sa.DateTime(), nullable=True, comment='Creation Time'),
    sa.ForeignKeyConstraint(['session_id'], ['prompt_opt_session_list.id'], ),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_prompt_opt_session_history_created_at'), 'prompt_opt_session_history', ['created_at'], unique=False)
    op.create_index(op.f('ix_prompt_opt_session_history_id'), 'prompt_opt_session_history', ['id'], unique=False)
    op.create_index('ix_prompt_opt_session_history_session_user_created', 'prompt_opt_session_history', ['session_id', 'user_id', 'created_at'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_prompt_opt_session_history_session_user_created', table_name='prompt_opt_session_history')
    op.drop_index(op.f('ix_prompt_opt_session_history_id'), table_name='prompt_opt_session_history')
    op.drop_index(op.f('ix_prompt_opt_session_history_created_at'), table_name='prompt_opt_session_history')
    op.drop_table('prompt_opt_session_history')
    op.drop_index(op.f('ix_prompt_opt_session_list_id'), table_name='prompt_opt_session_list')
    op.drop_index(op.f('ix_prompt_opt_session_list_created_at'), table_name='prompt_opt_session_list')
    op.drop_table('prompt_opt_session_list')
    op.drop_index(op.f('ix_prompt_model_config_id'), table_name='prompt_model_config')
    op.drop_table('prompt_model_config')
    # ### end Alembic commands ###
