"""add knowledge models
Revision ID: 0aa1fd6c1c28
Revises: 28c9cd2eb998
Create Date: 2025-11-03 16:28:16.647133
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = '0aa1fd6c1c28'
down_revision: Union[str, Sequence[str], None] = '28c9cd2eb998'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
op.create_table('knowledge_base',
sa.Column('kb_id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('owner_type', sa.String(length=50), nullable=False),
sa.Column('owner_id', sa.Integer(), nullable=True),
sa.Column('root_dir', sa.String(length=255), nullable=False),
sa.Column('index_dir', sa.String(length=255), nullable=True),
sa.Column('parser', sa.String(length=50), nullable=True),
sa.Column('parse_method', sa.String(length=20), nullable=True),
sa.Column('embed_model', sa.String(length=100), nullable=True),
sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('doc_count', sa.Integer(), nullable=False),
sa.Column('last_built_at', sa.TIMESTAMP(), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(), nullable=True),
sa.Column('updated_at', sa.TIMESTAMP(), nullable=True),
sa.PrimaryKeyConstraint('kb_id', name=op.f('pk_knowledge_base'))
)
op.create_table('knowledge_document',
sa.Column('doc_id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('kb_id', sa.Integer(), nullable=False),
sa.Column('file_path', sa.String(length=500), nullable=False),
sa.Column('file_name', sa.String(length=255), nullable=True),
sa.Column('md5', sa.String(length=64), nullable=True),
sa.Column('parse_status', sa.String(length=20), nullable=True),
sa.Column('chunks_count', sa.Integer(), nullable=False),
sa.Column('paper_meta', sa.JSON(), nullable=True),
sa.Column('failed_reason', sa.Text(), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(), nullable=True),
sa.Column('updated_at', sa.TIMESTAMP(), nullable=True),
sa.PrimaryKeyConstraint('doc_id', name=op.f('pk_knowledge_document'))
)
with op.batch_alter_table('knowledge_document', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_knowledge_document_kb_id'), ['kb_id'], unique=False)
with op.batch_alter_table('conference', schema=None) as batch_op:
batch_op.create_unique_constraint(batch_op.f('uq_conference_short_name_year'), ['short_name', 'year'])
def downgrade() -> None:
"""Downgrade schema."""
with op.batch_alter_table('conference', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('uq_conference_short_name_year'), type_='unique')
with op.batch_alter_table('knowledge_document', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_knowledge_document_kb_id'))
op.drop_table('knowledge_document')
op.drop_table('knowledge_base')