"""initial schema

Revision ID: 89efb0f02dc0
Revises: 
Create Date: 2026-03-03 10:51:24.248071

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '89efb0f02dc0'
down_revision: Union[str, Sequence[str], None] = None
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('sql_conversations',
    sa.Column('uuid', sa.String(length=36), nullable=False),
    sa.Column('user_db_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=500), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sql_conversations_user_db_id'), 'sql_conversations', ['user_db_id'], unique=False)
    op.create_index(op.f('ix_sql_conversations_uuid'), 'sql_conversations', ['uuid'], unique=True)
    op.create_table('sql_messages',
    sa.Column('uuid', sa.String(length=36), nullable=False),
    sa.Column('conversation_id', sa.Integer(), nullable=False),
    sa.Column('role', sa.String(length=20), nullable=False),
    sa.Column('content', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sql_messages_conversation_id'), 'sql_messages', ['conversation_id'], unique=False)
    op.create_index(op.f('ix_sql_messages_uuid'), 'sql_messages', ['uuid'], unique=True)
    op.create_table('sql_queries',
    sa.Column('uuid', sa.String(length=36), nullable=False),
    sa.Column('message_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=500), nullable=True),
    sa.Column('sql', sa.Text(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sql_queries_message_id'), 'sql_queries', ['message_id'], unique=False)
    op.create_index(op.f('ix_sql_queries_uuid'), 'sql_queries', ['uuid'], unique=True)
    op.create_table('user_dbs',
    sa.Column('uuid', sa.String(length=36), nullable=False),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('connection_string', sa.Text(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_user_dbs_uuid'), 'user_dbs', ['uuid'], unique=True)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_user_dbs_uuid'), table_name='user_dbs')
    op.drop_table('user_dbs')
    op.drop_index(op.f('ix_sql_queries_uuid'), table_name='sql_queries')
    op.drop_index(op.f('ix_sql_queries_message_id'), table_name='sql_queries')
    op.drop_table('sql_queries')
    op.drop_index(op.f('ix_sql_messages_uuid'), table_name='sql_messages')
    op.drop_index(op.f('ix_sql_messages_conversation_id'), table_name='sql_messages')
    op.drop_table('sql_messages')
    op.drop_index(op.f('ix_sql_conversations_uuid'), table_name='sql_conversations')
    op.drop_index(op.f('ix_sql_conversations_user_db_id'), table_name='sql_conversations')
    op.drop_table('sql_conversations')
    # ### end Alembic commands ###
