"""20251118191055

Revision ID: 29c030316adf
Revises: 2df9cdfc5087
Create Date: 2025-11-18 19:10:56.550902

"""
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 = '29c030316adf'
down_revision: Union[str, None] = '2df9cdfc5087'
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('app_shares',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('source_app_id', sa.UUID(), nullable=False, comment='源应用ID'),
    sa.Column('source_workspace_id', sa.UUID(), nullable=False, comment='源工作空间ID'),
    sa.Column('target_workspace_id', sa.UUID(), nullable=False, comment='目标工作空间ID'),
    sa.Column('shared_by', sa.UUID(), nullable=False, comment='分享者用户ID'),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['shared_by'], ['users.id'], ),
    sa.ForeignKeyConstraint(['source_app_id'], ['apps.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['source_workspace_id'], ['workspaces.id'], ),
    sa.ForeignKeyConstraint(['target_workspace_id'], ['workspaces.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_app_shares_id'), 'app_shares', ['id'], unique=False)
    op.drop_table('data_config')
    op.add_column('conversations', sa.Column('workspace_id', sa.UUID(), nullable=False, comment='工作空间ID'))
    op.create_foreign_key(None, 'conversations', 'workspaces', ['workspace_id'], ['id'])
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'conversations', type_='foreignkey')
    op.drop_column('conversations', 'workspace_id')
    op.create_table('data_config',
    sa.Column('config_id', sa.BIGINT(), sa.Identity(always=True, start=1, increment=1, minvalue=1, maxvalue=9223372036854775807, cycle=False, cache=1), autoincrement=True, nullable=False),
    sa.Column('config_name', sa.VARCHAR(length=255), server_default=sa.text("'配置文件'::character varying"), autoincrement=False, nullable=False),
    sa.Column('group_id', sa.VARCHAR(length=255), server_default=sa.text("'group_id'::character varying"), autoincrement=False, nullable=False),
    sa.Column('user_id', sa.VARCHAR(length=255), server_default=sa.text("'user_id'::character varying"), autoincrement=False, nullable=False),
    sa.Column('apply_id', sa.VARCHAR(length=255), server_default=sa.text("'apply_id'::character varying"), autoincrement=False, nullable=False),
    sa.Column('enable_llm_dedup_blockwise', sa.BOOLEAN(), server_default=sa.text('true'), autoincrement=False, nullable=False),
    sa.Column('enable_llm_disambiguation', sa.BOOLEAN(), server_default=sa.text('true'), autoincrement=False, nullable=False),
    sa.Column('deep_retrieval', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False),
    sa.Column('t_type_strict', sa.NUMERIC(), server_default=sa.text('0.5'), autoincrement=False, nullable=False),
    sa.Column('t_name_strict', sa.NUMERIC(), server_default=sa.text('0.8'), autoincrement=False, nullable=False),
    sa.Column('t_overall', sa.NUMERIC(), server_default=sa.text('0.56'), autoincrement=False, nullable=False),
    sa.Column('chunker_strategy', postgresql.ENUM('RecursiveChunker', 'TokenChunker', 'SemanticChunker', 'NeuralChunker', 'HybridChunker', 'LLMChunker', 'SentenceChunker', 'LateChunker', name='chunker_strategy_enum'), server_default=sa.text("'RecursiveChunker'::chunker_strategy_enum"), autoincrement=False, nullable=False, comment='选择分块策略：    \r\n    "RecursiveChunker",\r\n    "TokenChunker",\r\n    "SemanticChunker",\r\n    "NeuralChunker",\r\n    "HybridChunker",\r\n    "LLMChunker",\r\n    "SentenceChunker",\r\n    "LateChunker"'),
    sa.Column('statement_granularity', sa.VARCHAR(length=255), server_default=sa.text("'2'::character varying"), autoincrement=False, nullable=True),
    sa.Column('include_dialogue_context', sa.BOOLEAN(), server_default=sa.text('true'), autoincrement=False, nullable=True),
    sa.Column('max_context', sa.VARCHAR(length=255), server_default=sa.text("'200'::character varying"), autoincrement=False, nullable=True),
    sa.Column('λ_time', sa.NUMERIC(), server_default=sa.text('0.3'), autoincrement=False, nullable=True),
    sa.Column('λ_mem', sa.NUMERIC(), server_default=sa.text('0.4'), autoincrement=False, nullable=True),
    sa.Column('offset', sa.NUMERIC(precision=255, scale=0), server_default=sa.text('0.56'), autoincrement=False, nullable=True),
    sa.Column('state', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True, precision=6), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True, precision=6), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=False),
    sa.Column('config_desc', sa.TEXT(), server_default=sa.text("'配置文件描述'::text"), autoincrement=False, nullable=False),
    sa.Column('workspace_id', sa.VARCHAR(length=255), server_default=sa.text("'workspace_id'::character varying"), autoincrement=False, nullable=False),
    sa.Column('enable_self_reflexion', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=True),
    sa.Column('iteration_period', sa.VARCHAR(length=50), server_default=sa.text("'三小时'::character varying"), autoincrement=False, nullable=True),
    sa.Column('baseline', sa.VARCHAR(length=50), server_default=sa.text("'时间'::character varying"), autoincrement=False, nullable=True),
    sa.Column('reflexion_range', sa.VARCHAR(length=25), server_default=sa.text("'部分'::character varying"), autoincrement=False, nullable=True),
    sa.Column('pruning_enabled', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=True),
    sa.Column('pruning_scene', sa.VARCHAR(length=255), server_default=sa.text("'education'::character varying"), autoincrement=False, nullable=True),
    sa.Column('pruning_threshold', sa.REAL(), server_default=sa.text('0.3'), autoincrement=False, nullable=True),
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=True)
    )
    op.drop_index(op.f('ix_app_shares_id'), table_name='app_shares')
    op.drop_table('app_shares')
    # ### end Alembic commands ###
