"""Create sentiment scores table

Revision ID: 0004
Revises: 0003
Create Date: 2026-01-17 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0004'
down_revision = '0003'
branch_labels = None
depends_on = None


def upgrade() -> None:
    """Create sentiment_scores table."""
    op.create_table(
        'sentiment_scores',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('entity_id', sa.String(length=255), nullable=False),
        sa.Column('entity_type', sa.String(length=50), nullable=False),
        sa.Column('score', sa.Float(), nullable=False),
        sa.Column('sentiment_type', sa.String(length=20), nullable=False),
        sa.Column('positive', sa.Float(), nullable=False, server_default='0.0'),
        sa.Column('negative', sa.Float(), nullable=False, server_default='0.0'),
        sa.Column('neutral', sa.Float(), nullable=False, server_default='0.0'),
        sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.text('(CURRENT_TIMESTAMP)')),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sentiment_scores_id'), 'sentiment_scores', ['id'], unique=False)
    op.create_index(op.f('ix_sentiment_scores_entity_id'), 'sentiment_scores', ['entity_id'], unique=False)
    op.create_index(op.f('ix_sentiment_scores_entity_type'), 'sentiment_scores', ['entity_type'], unique=False)
    op.create_index(op.f('ix_sentiment_scores_score'), 'sentiment_scores', ['score'], unique=False)
    op.create_index(op.f('ix_sentiment_scores_sentiment_type'), 'sentiment_scores', ['sentiment_type'], unique=False)
    op.create_index(op.f('ix_sentiment_scores_created_at'), 'sentiment_scores', ['created_at'], unique=False)
    op.create_index('idx_sentiment_scores_entity', 'sentiment_scores', ['entity_id', 'entity_type'], unique=False)


def downgrade() -> None:
    """Drop sentiment_scores table."""
    # Drop indexes
    op.drop_index('idx_sentiment_scores_entity', table_name='sentiment_scores')
    op.drop_index(op.f('ix_sentiment_scores_created_at'), table_name='sentiment_scores')
    op.drop_index(op.f('ix_sentiment_scores_sentiment_type'), table_name='sentiment_scores')
    op.drop_index(op.f('ix_sentiment_scores_score'), table_name='sentiment_scores')
    op.drop_index(op.f('ix_sentiment_scores_entity_type'), table_name='sentiment_scores')
    op.drop_index(op.f('ix_sentiment_scores_entity_id'), table_name='sentiment_scores')
    op.drop_index(op.f('ix_sentiment_scores_id'), table_name='sentiment_scores')

    # Drop table
    op.drop_table('sentiment_scores')
