"""create rss_articles table

Revision ID: 20260117_0007
Revises: 20260117_0006
Create Date: 2026-01-17

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import create_engine


# revision identifiers, used by Alembic.
revision = '20260117_0007'
down_revision = '20260117_0006'
branch_labels = None
depends_on = None


def upgrade() -> None:
    """Create rss_articles table."""
    op.create_table(
        'rss_articles',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('article_id', sa.String(length=255), nullable=False),
        sa.Column('title', sa.String(length=500), nullable=False),
        sa.Column('content', sa.Text(), nullable=True),
        sa.Column('published_at', sa.DateTime(), nullable=False),
        sa.Column('source_url', sa.String(length=1000), nullable=False),
        sa.Column('match_id', sa.Integer(), nullable=True),
        sa.Column('source', sa.String(length=100), nullable=True, server_default='rss'),
        sa.PrimaryKeyConstraint('id')
    )
    
    op.create_index('ix_rss_articles_id', 'rss_articles', ['id'])
    op.create_index('ix_rss_articles_article_id', 'rss_articles', ['article_id'])
    op.create_index('ix_rss_articles_published_at', 'rss_articles', ['published_at'])
    op.create_index('ix_rss_articles_match_id', 'rss_articles', ['match_id'])
    op.create_index('idx_rss_articles_match_id_source', 'rss_articles', ['match_id', 'source'])
    op.create_index('idx_rss_articles_published_at', 'rss_articles', ['published_at'])
    op.create_index('idx_rss_articles_source_url', 'rss_articles', ['source_url'])


def downgrade() -> None:
    """Drop rss_articles table."""
    op.drop_index('idx_rss_articles_source_url', table_name='rss_articles')
    op.drop_index('idx_rss_articles_published_at', table_name='rss_articles')
    op.drop_index('idx_rss_articles_match_id_source', table_name='rss_articles')
    op.drop_index('ix_rss_articles_match_id', table_name='rss_articles')
    op.drop_index('ix_rss_articles_published_at', table_name='rss_articles')
    op.drop_index('ix_rss_articles_article_id', table_name='rss_articles')
    op.drop_index('ix_rss_articles_id', table_name='rss_articles')
    op.drop_table('rss_articles')
