"""202601071800

Revision ID: c6d4afa27bf0
Revises: 8372101eda28
Create Date: 2026-01-07 17:59:23.032323

"""
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 = 'c6d4afa27bf0'
down_revision: Union[str, None] = '8372101eda28'
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('memory_long_term',
    sa.Column('id', sa.UUID(), nullable=False, comment='记忆ID'),
    sa.Column('end_user_id', sa.String(length=255), nullable=False, comment='终端用户ID'),
    sa.Column('retrieved_content', sa.JSON(), nullable=True, comment='检索到的相关内容，格式为[{}, {}]'),
    sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_memory_long_term_created_at'), 'memory_long_term', ['created_at'], unique=False)
    op.create_index(op.f('ix_memory_long_term_end_user_id'), 'memory_long_term', ['end_user_id'], unique=False)
    op.create_index(op.f('ix_memory_long_term_id'), 'memory_long_term', ['id'], unique=False)
    op.create_table('memory_short_term',
    sa.Column('id', sa.UUID(), nullable=False, comment='记忆ID'),
    sa.Column('end_user_id', sa.String(length=255), nullable=False, comment='终端用户ID'),
    sa.Column('messages', sa.Text(), nullable=False, comment='用户消息内容'),
    sa.Column('aimessages', sa.Text(), nullable=True, comment='AI回复消息内容'),
    sa.Column('search_switch', sa.String(length=50), nullable=True, comment='搜索开关状态'),
    sa.Column('retrieved_content', sa.JSON(), nullable=True, comment='检索到的相关内容，格式为[{}, {}]'),
    sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_memory_short_term_created_at'), 'memory_short_term', ['created_at'], unique=False)
    op.create_index(op.f('ix_memory_short_term_end_user_id'), 'memory_short_term', ['end_user_id'], unique=False)
    op.create_index(op.f('ix_memory_short_term_id'), 'memory_short_term', ['id'], unique=False)
    op.create_table('memory_perceptual',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('end_user_id', sa.UUID(), nullable=True),
    sa.Column('perceptual_type', sa.Integer(), nullable=False, comment='感知类型'),
    sa.Column('storage_service', sa.Integer(), nullable=True, comment='存储服务类型'),
    sa.Column('file_path', sa.String(), nullable=False, comment='文件路径'),
    sa.Column('file_name', sa.String(), nullable=False, comment='文件名称'),
    sa.Column('file_ext', sa.String(), nullable=False, comment='文件后缀名'),
    sa.Column('summary', sa.String(), nullable=True, comment='摘要'),
    sa.Column('meta_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True, comment='元信息'),
    sa.Column('created_time', sa.DateTime(), nullable=True, comment='创建时间'),
    sa.ForeignKeyConstraint(['end_user_id'], ['end_users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_memory_perceptual_end_user_id'), 'memory_perceptual', ['end_user_id'], unique=False)
    op.create_index(op.f('ix_memory_perceptual_perceptual_type'), 'memory_perceptual', ['perceptual_type'], unique=False)
    op.alter_column('multi_agent_configs', 'orchestration_mode',
               existing_type=sa.VARCHAR(length=20),
               comment='协作模式: collaboration（协作）| supervisor（监督）',
               existing_comment='协作模式: sequential|parallel|conditional|loop',
               existing_nullable=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('multi_agent_configs', 'orchestration_mode',
               existing_type=sa.VARCHAR(length=20),
               comment='协作模式: sequential|parallel|conditional|loop',
               existing_comment='协作模式: collaboration（协作）| supervisor（监督）',
               existing_nullable=False)
    op.drop_index(op.f('ix_memory_perceptual_perceptual_type'), table_name='memory_perceptual')
    op.drop_index(op.f('ix_memory_perceptual_end_user_id'), table_name='memory_perceptual')
    op.drop_table('memory_perceptual')
    op.drop_index(op.f('ix_memory_short_term_id'), table_name='memory_short_term')
    op.drop_index(op.f('ix_memory_short_term_end_user_id'), table_name='memory_short_term')
    op.drop_index(op.f('ix_memory_short_term_created_at'), table_name='memory_short_term')
    op.drop_table('memory_short_term')
    op.drop_index(op.f('ix_memory_long_term_id'), table_name='memory_long_term')
    op.drop_index(op.f('ix_memory_long_term_end_user_id'), table_name='memory_long_term')
    op.drop_index(op.f('ix_memory_long_term_created_at'), table_name='memory_long_term')
    op.drop_table('memory_long_term')
    # ### end Alembic commands ###
