"""playback_sources.dead_at + dead_reason — flagging dead tube links

Revision ID: 0003_playback_dead
Revises: 0002_playback_sources
Create Date: 2026-05-03

Gdy resolve endpoint dostanie 404 "Video is offline" / "deleted" z porn-app,
oznaczamy ten playback_source jako martwy. API filtruje go z `_build_scene_out`,
mobile go nie pokazuje. has_playback=true filter też wymaga `dead_at IS NULL`.
"""
from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

revision: str = "0003_playback_dead"
down_revision: str | None = "0002_playback_sources"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    op.add_column(
        "playback_sources",
        sa.Column("dead_at", sa.DateTime(timezone=True), nullable=True),
    )
    op.add_column(
        "playback_sources",
        sa.Column("dead_reason", sa.String(length=512), nullable=True),
    )
    op.create_index(
        "ix_playback_sources_dead_at",
        "playback_sources",
        ["dead_at"],
    )


def downgrade() -> None:
    op.drop_index("ix_playback_sources_dead_at", table_name="playback_sources")
    op.drop_column("playback_sources", "dead_reason")
    op.drop_column("playback_sources", "dead_at")
