"""tracks: enrichment outcome (error reason + completion time)

Revision ID: 20260613_enrich_outcome
Revises: 20260608_subsonic_pw
Create Date: 2026-06-13 13:00:00.000000

Adds ``tracks.metadata_error`` and ``tracks.enriched_at`` so a finished
enrichment run records *why* it failed and *when* it completed. Lets the UI
distinguish a still-pending/running track from one that is done or failed, and
surface an actionable reason instead of a silent spinner (plan §6.2).
"""

from __future__ import annotations

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

revision: str = "20260613_enrich_outcome"
down_revision: str | None = "20260608_subsonic_pw"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    op.add_column(
        "tracks",
        sa.Column("metadata_error", sa.String(length=2048), nullable=True),
    )
    op.add_column(
        "tracks",
        sa.Column("enriched_at", sa.DateTime(timezone=True), nullable=True),
    )


def downgrade() -> None:
    op.drop_column("tracks", "enriched_at")
    op.drop_column("tracks", "metadata_error")
