"""Blacklists — performers/studios/tags do globalnego ukrywania.

Revision ID: 0006_blacklists
Revises: 0005_favorite_performers
Create Date: 2026-05-04

Single-user; analogicznie do favorite_performers ale negative — sceny które MAJĄ
blacklisted performer / studio / tag są wykluczane ze wszystkich list (scenes,
search, performer/tag scenes).
"""
from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

revision: str = "0006_blacklists"
down_revision: str | None = "0005_favorite_performers"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    for tbl, parent_tbl, parent_col in [
        ("blacklisted_performers", "performers", "performer_id"),
        ("blacklisted_studios", "studios", "studio_id"),
        ("blacklisted_tags", "tags", "tag_id"),
    ]:
        op.create_table(
            tbl,
            sa.Column(parent_col, sa.dialects.postgresql.UUID(as_uuid=True),
                      sa.ForeignKey(f"{parent_tbl}.id", ondelete="CASCADE"),
                      primary_key=True),
            sa.Column("created_at", sa.DateTime(timezone=True),
                      server_default=sa.func.now(), nullable=False),
        )


def downgrade() -> None:
    op.drop_table("blacklisted_tags")
    op.drop_table("blacklisted_studios")
    op.drop_table("blacklisted_performers")
