"""Create Reddit posts and comments tables

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

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    """Create Reddit posts and comments tables."""
    # Create posts_reddit table
    op.create_table(
        'posts_reddit',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('post_id', sa.String(length=255), nullable=False),
        sa.Column('title', sa.String(length=500), nullable=False),
        sa.Column('text', sa.Text(), nullable=True),
        sa.Column('upvotes', sa.Integer(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('match_id', sa.Integer(), nullable=True),
        sa.Column('subreddit', sa.String(length=100), nullable=False),
        sa.Column('source', sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_posts_reddit_created_at'), 'posts_reddit', ['created_at'], unique=False)
    op.create_index(op.f('ix_posts_reddit_id'), 'posts_reddit', ['id'], unique=False)
    op.create_index(op.f('ix_posts_reddit_match_id'), 'posts_reddit', ['match_id'], unique=False)
    op.create_index(op.f('ix_posts_reddit_post_id'), 'posts_reddit', ['post_id'], unique=True)
    op.create_index(op.f('ix_posts_reddit_subreddit'), 'posts_reddit', ['subreddit'], unique=False)

    # Create comments_reddit table
    op.create_table(
        'comments_reddit',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('comment_id', sa.String(length=255), nullable=False),
        sa.Column('post_id', sa.String(length=255), nullable=False),
        sa.Column('text', sa.Text(), nullable=False),
        sa.Column('upvotes', sa.Integer(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('source', sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_comments_reddit_created_at'), 'comments_reddit', ['created_at'], unique=False)
    op.create_index(op.f('ix_comments_reddit_id'), 'comments_reddit', ['id'], unique=False)
    op.create_index(op.f('ix_comments_reddit_comment_id'), 'comments_reddit', ['comment_id'], unique=True)
    op.create_index(op.f('ix_comments_reddit_post_id'), 'comments_reddit', ['post_id'], unique=False)


def downgrade() -> None:
    """Drop Reddit posts and comments tables."""
    # Drop comments_reddit table
    op.drop_index(op.f('ix_comments_reddit_post_id'), table_name='comments_reddit')
    op.drop_index(op.f('ix_comments_reddit_comment_id'), table_name='comments_reddit')
    op.drop_index(op.f('ix_comments_reddit_id'), table_name='comments_reddit')
    op.drop_index(op.f('ix_comments_reddit_created_at'), table_name='comments_reddit')
    op.drop_table('comments_reddit')

    # Drop posts_reddit table
    op.drop_index(op.f('ix_posts_reddit_subreddit'), table_name='posts_reddit')
    op.drop_index(op.f('ix_posts_reddit_post_id'), table_name='posts_reddit')
    op.drop_index(op.f('ix_posts_reddit_match_id'), table_name='posts_reddit')
    op.drop_index(op.f('ix_posts_reddit_id'), table_name='posts_reddit')
    op.drop_index(op.f('ix_posts_reddit_created_at'), table_name='posts_reddit')
    op.drop_table('posts_reddit')
