"""plex_people: a small cast/crew headshot cache for person filter-chips

Revision ID: 0056_plex_people
Revises: 0055_channel_keywords
Create Date: 2026-07-19
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

revision: str = "0056_plex_people"
down_revision: Union[str, None] = "0055_channel_keywords"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "plex_people",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("name", sa.String(length=255), nullable=False),
        # A representative proxied headshot URL (or NULL when none is available). Captured
        # opportunistically from an item's rich metadata (info-page view + the rich re-sync).
        sa.Column("photo_thumb", sa.Text(), nullable=True),
        sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
    )
    op.create_index("ix_plex_people_name", "plex_people", ["name"], unique=True)


def downgrade() -> None:
    op.drop_index("ix_plex_people_name", table_name="plex_people")
    op.drop_table("plex_people")
