"""202601221030

Revision ID: 9a936a9ebb20
Revises: 8cd790908f92
Create Date: 2026-01-22 10:27:10.840844

"""
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 = '9a936a9ebb20'
down_revision: Union[str, None] = '8cd790908f92'
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('file_metadata',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('tenant_id', sa.UUID(), nullable=False, comment='Tenant ID'),
    sa.Column('workspace_id', sa.UUID(), nullable=False, comment='Workspace ID'),
    sa.Column('file_key', sa.String(length=512), nullable=False, comment='Storage file key'),
    sa.Column('file_name', sa.String(length=255), nullable=False, comment='Original file name'),
    sa.Column('file_ext', sa.String(length=32), nullable=False, comment='File extension'),
    sa.Column('file_size', sa.Integer(), nullable=False, comment='File size in bytes'),
    sa.Column('content_type', sa.String(length=128), nullable=True, comment='MIME content type'),
    sa.Column('status', sa.String(length=16), nullable=False, comment='Upload status: pending, completed, failed'),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_file_metadata_file_key'), 'file_metadata', ['file_key'], unique=True)
    op.create_index(op.f('ix_file_metadata_id'), 'file_metadata', ['id'], unique=False)
    op.create_index(op.f('ix_file_metadata_tenant_id'), 'file_metadata', ['tenant_id'], unique=False)
    op.create_index(op.f('ix_file_metadata_workspace_id'), 'file_metadata', ['workspace_id'], unique=False)
    op.drop_index(op.f('ix_emotion_suggestions_cache_end_user_id'), table_name='emotion_suggestions_cache')
    op.drop_index(op.f('ix_emotion_suggestions_cache_id'), table_name='emotion_suggestions_cache')
    op.drop_table('emotion_suggestions_cache')
    op.drop_index(op.f('ix_implicit_memory_cache_end_user_id'), table_name='implicit_memory_cache')
    op.drop_index(op.f('ix_implicit_memory_cache_id'), table_name='implicit_memory_cache')
    op.drop_table('implicit_memory_cache')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('implicit_memory_cache',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('end_user_id', sa.VARCHAR(length=255), autoincrement=False, nullable=False, comment='终端用户ID'),
    sa.Column('preferences', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False, comment='偏好标签列表（JSON格式）'),
    sa.Column('portrait', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False, comment='四维画像对象（JSON格式）'),
    sa.Column('interest_areas', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False, comment='兴趣领域分布对象（JSON格式）'),
    sa.Column('habits', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False, comment='行为习惯列表（JSON格式）'),
    sa.Column('generated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False, comment='生成时间'),
    sa.Column('expires_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True, comment='过期时间'),
    sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('implicit_memory_cache_pkey'))
    )
    op.create_index(op.f('ix_implicit_memory_cache_id'), 'implicit_memory_cache', ['id'], unique=False)
    op.create_index(op.f('ix_implicit_memory_cache_end_user_id'), 'implicit_memory_cache', ['end_user_id'], unique=True)
    op.create_table('emotion_suggestions_cache',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('end_user_id', sa.VARCHAR(length=255), autoincrement=False, nullable=False, comment='终端用户ID（组ID）'),
    sa.Column('health_summary', sa.TEXT(), autoincrement=False, nullable=False, comment='健康状态摘要'),
    sa.Column('suggestions', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False, comment='建议列表（JSON格式）'),
    sa.Column('generated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False, comment='生成时间'),
    sa.Column('expires_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True, comment='过期时间'),
    sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('emotion_suggestions_cache_pkey'))
    )
    op.create_index(op.f('ix_emotion_suggestions_cache_id'), 'emotion_suggestions_cache', ['id'], unique=False)
    op.create_index(op.f('ix_emotion_suggestions_cache_end_user_id'), 'emotion_suggestions_cache', ['end_user_id'], unique=True)
    op.drop_index(op.f('ix_file_metadata_workspace_id'), table_name='file_metadata')
    op.drop_index(op.f('ix_file_metadata_tenant_id'), table_name='file_metadata')
    op.drop_index(op.f('ix_file_metadata_id'), table_name='file_metadata')
    op.drop_index(op.f('ix_file_metadata_file_key'), table_name='file_metadata')
    op.drop_table('file_metadata')
    # ### end Alembic commands ###
