"""sessions add index update_time

Revision ID: 3091a16c34a6
Revises: 
Create Date: 2025-01-15 18:07:00.151468

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = '3091a16c34a6'
down_revision: Union[str, None] = None
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.drop_table('knowledgebase')
    op.drop_table('user_tenant')
    op.drop_table('apps')
    op.drop_table('flow')
    op.create_index(op.f('ix_sessions_update_date'), 'sessions', ['update_date'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_sessions_update_date'), table_name='sessions')
    op.add_column('dialogs', sa.Column('parameters', mysql.TEXT(), nullable=True))
    op.create_table('flow',
    sa.Column('id', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('name', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('status', mysql.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('description', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('user_id', mysql.INTEGER(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_table('apps',
    sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('name', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('status', mysql.VARCHAR(length=16), nullable=False),
    sa.Column('description', mysql.TEXT(), nullable=False),
    sa.Column('tenant_id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('mode', mysql.VARCHAR(length=36), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_table('user_tenant',
    sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('tenant_id', mysql.VARCHAR(length=32), nullable=True),
    sa.Column('user_id', mysql.VARCHAR(length=32), nullable=True),
    sa.Column('role', mysql.VARCHAR(length=32), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_table('knowledgebase',
    sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('name', mysql.VARCHAR(length=128), nullable=True),
    sa.Column('permission', mysql.VARCHAR(length=32), nullable=True),
    sa.Column('tenant_id', mysql.VARCHAR(length=32), nullable=True),
    sa.Column('description', mysql.TEXT(), nullable=True),
    sa.Column('status', mysql.VARCHAR(length=1), nullable=True),
    sa.Column('doc_num', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_table('chat_sessions',
    sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('name', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('agent_id', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('agent_type', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('create_date', mysql.DATETIME(), nullable=True),
    sa.Column('update_date', mysql.DATETIME(), nullable=True),
    sa.Column('tenant_id', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('message', mysql.TEXT(), nullable=True),
    sa.Column('reference', mysql.TEXT(), nullable=True),
    sa.Column('conversation_id', mysql.VARCHAR(length=36), nullable=True),
    sa.Column('event_type', mysql.VARCHAR(length=16), nullable=True),
    sa.Column('session_type', mysql.VARCHAR(length=16), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_index('ix_chat_sessions_update_date', 'chat_sessions', ['update_date'], unique=False)
    op.create_index('ix_chat_sessions_tenant_id', 'chat_sessions', ['tenant_id'], unique=False)
    op.create_index('ix_chat_sessions_conversation_id', 'chat_sessions', ['conversation_id'], unique=False)
    op.create_table('dialog',
    sa.Column('id', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('name', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('status', mysql.VARCHAR(length=1), nullable=False),
    sa.Column('description', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('tenant_id', mysql.VARCHAR(length=36), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_table('chat_api_tokens',
    sa.Column('id', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=36), nullable=False),
    sa.Column('app_id', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=36), nullable=True),
    sa.Column('type', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=16), nullable=True),
    sa.Column('token', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=255), nullable=True),
    sa.Column('created_at', mysql.DATETIME(), nullable=True),
    sa.Column('last_used_at', mysql.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8mb3',
    mysql_engine='InnoDB',
    mysql_row_format='DYNAMIC'
    )
    op.create_index('ix_chat_api_tokens_app_id', 'chat_api_tokens', ['app_id'], unique=False)
    op.create_table('user_token',
    sa.Column('id', mysql.VARCHAR(length=16), nullable=False),
    sa.Column('account', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('password', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('access_token', mysql.VARCHAR(length=1000), nullable=True),
    sa.Column('refresh_token', mysql.VARCHAR(length=1000), nullable=True),
    sa.Column('created_at', mysql.DATETIME(), nullable=True),
    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    # ### end Alembic commands ###
