"""Add sentiment analysis fields to citation_records

Revision ID: d4e6f8a0bc13
Revises: c3d5e7f9ab12
Create Date: 2026-05-19 10:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'd4e6f8a0bc13'
down_revision: Union[str, Sequence[str], None] = 'c3d5e7f9ab12'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # 添加情感分析字段
    op.add_column('citation_records',
        sa.Column('sentiment', sa.String(20), nullable=True,
                  comment='情感倾向: positive / neutral / negative')
    )
    op.add_column('citation_records',
        sa.Column('sentiment_confidence', sa.Float(), nullable=True,
                  comment='情感分析置信度 0.0-1.0')
    )
    op.add_column('citation_records',
        sa.Column('sentiment_key_phrases', sa.JSON(), nullable=True,
                  comment='关键情感短语列表')
    )


def downgrade() -> None:
    op.drop_column('citation_records', 'sentiment_key_phrases')
    op.drop_column('citation_records', 'sentiment_confidence')
    op.drop_column('citation_records', 'sentiment')
