"""import_task.recovery_count + refetched — poison-pill circuit breaker

Revision ID: 0026
Revises: 0025
Create Date: 2026-05-28

Backs the import-task resilience work (operator-flagged 2026-05-28):

- recovery_count: how many times recover_interrupted_tasks has
  re-queued this row from a stuck 'processing' state. A row that
  hard-crashes the worker (OOM / segfault on a corrupt or oversized
  input) leaves no terminal flip, so the sweep re-queues it — and
  without a cap it would loop forever, re-crashing the worker each
  time. After MAX_RECOVERY_ATTEMPTS the sweep marks it 'failed' with a
  diagnostic instead.

- refetched: whether a one-shot re-download has already been attempted
  for this task's file. Bounds the Layer-2 re-fetch remediation to a
  single attempt so source-side corruption doesn't loop.

Both default to 0 / false; additive, no backfill needed.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0026"
down_revision: Union[str, None] = "0025"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "import_task",
        sa.Column(
            "recovery_count", sa.Integer(), nullable=False,
            server_default="0",
        ),
    )
    op.add_column(
        "import_task",
        sa.Column(
            "refetched", sa.Boolean(), nullable=False,
            server_default=sa.false(),
        ),
    )


def downgrade() -> None:
    op.drop_column("import_task", "refetched")
    op.drop_column("import_task", "recovery_count")
