"""Add creator_follows table for user follow system.

Revision ID: 022_add_creator_follows
Revises: 021_add_highlight_trim_columns
"""

from alembic import op


revision = "022_add_creator_follows"
down_revision = "021_add_highlight_trim_columns"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute("""
        CREATE TABLE IF NOT EXISTS creator_follows (
            id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
            user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
            creator_id UUID NOT NULL REFERENCES creators(id) ON DELETE CASCADE,
            created_at TIMESTAMP NOT NULL DEFAULT now(),
            CONSTRAINT uq_creator_follow_user_creator UNIQUE (user_id, creator_id)
        )
    """)
    op.execute("CREATE INDEX IF NOT EXISTS ix_creator_follows_user_id ON creator_follows (user_id)")
    op.execute("CREATE INDEX IF NOT EXISTS ix_creator_follows_creator_id ON creator_follows (creator_id)")


def downgrade() -> None:
    op.execute("DROP TABLE IF EXISTS creator_follows")
