"""source.error_type: surface ErrorType taxonomy in FailingSourcesCard

Revision ID: 0032
Revises: 0031
Create Date: 2026-06-02

Audit 2026-06-02: the backend computes 13 ErrorType categories (auth_error,
rate_limited, not_found, access_denied, validation_failed, etc.) and
stamps each one on DownloadEvent.metadata, but the Source row only carried
the free-text last_error. Operators couldn't bulk-triage failing sources
("all auth_error → rotate cookies, all rate_limited → just wait") without
opening Logs per row.

This column receives the last error_type from _update_source_health
and gets cleared on a successful run. Nullable + indexed so the failing-
sources rollup can filter/group cheaply.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0032"
down_revision: Union[str, None] = "0031"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "source",
        sa.Column("error_type", sa.String(length=32), nullable=True),
    )
    op.create_index(
        "ix_source_error_type", "source", ["error_type"],
    )


def downgrade() -> None:
    op.drop_index("ix_source_error_type", table_name="source")
    op.drop_column("source", "error_type")
