"""202601301521

Revision ID: 550c10595967
Revises: 5de9b1e28509
Create Date: 2026-01-30 15:24:34.647440

"""
from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = '550c10595967'
down_revision: Union[str, None] = '5de9b1e28509'
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('ontology_scene',
    sa.Column('scene_id', sa.UUID(), nullable=False, comment='场景ID'),
    sa.Column('scene_name', sa.String(length=200), nullable=False, comment='场景名称'),
    sa.Column('scene_description', sa.Text(), nullable=True, comment='场景描述'),
    sa.Column('workspace_id', sa.UUID(), nullable=False, comment='所属工作空间ID'),
    sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'),
    sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('scene_id'),
    sa.UniqueConstraint('workspace_id', 'scene_name', name='uq_workspace_scene_name')
    )
    op.create_index(op.f('ix_ontology_scene_scene_id'), 'ontology_scene', ['scene_id'], unique=False)
    op.create_index(op.f('ix_ontology_scene_workspace_id'), 'ontology_scene', ['workspace_id'], unique=False)
    op.create_table('ontology_class',
    sa.Column('class_id', sa.UUID(), nullable=False, comment='类型ID'),
    sa.Column('class_name', sa.String(length=200), nullable=False, comment='类型名称'),
    sa.Column('class_description', sa.Text(), nullable=True, comment='类型描述'),
    sa.Column('scene_id', sa.UUID(), nullable=False, comment='所属场景ID'),
    sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'),
    sa.ForeignKeyConstraint(['scene_id'], ['ontology_scene.scene_id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('class_id')
    )
    op.create_index(op.f('ix_ontology_class_class_id'), 'ontology_class', ['class_id'], unique=False)
    op.create_index(op.f('ix_ontology_class_scene_id'), 'ontology_class', ['scene_id'], unique=False)
    op.create_table('prompt_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('title', sa.String(), nullable=False, comment='Title'),
    sa.Column('prompt', sa.Text(), nullable=False, comment='Prompt'),
    sa.Column('created_at', sa.DateTime(), nullable=True, comment='Creation Time'),
    sa.Column('is_delete', sa.Boolean(), nullable=True, comment='Delete'),
    sa.ForeignKeyConstraint(['session_id'], ['prompt_opt_session_list.id'], ),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_prompt_history_created_at'), 'prompt_history', ['created_at'], unique=False)
    op.create_index(op.f('ix_prompt_history_id'), 'prompt_history', ['id'], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###

    op.drop_index(op.f('ix_prompt_history_id'), table_name='prompt_history')
    op.drop_index(op.f('ix_prompt_history_created_at'), table_name='prompt_history')
    op.drop_table('prompt_history')
    op.drop_index(op.f('ix_ontology_class_scene_id'), table_name='ontology_class')
    op.drop_index(op.f('ix_ontology_class_class_id'), table_name='ontology_class')
    op.drop_table('ontology_class')
    op.drop_index(op.f('ix_ontology_scene_workspace_id'), table_name='ontology_scene')
    op.drop_index(op.f('ix_ontology_scene_scene_id'), table_name='ontology_scene')
    op.drop_table('ontology_scene')
    # ### end Alembic commands ###
