"""retire the Camie tagger + allowlist bulk-apply (#1189)

The v2 pivot made heads + CCIP the tag source and head auto-apply the earned
propagation. The Camie tagger ran only to feed the allowlist bulk-apply (its
predictions had no other consumer), and the allowlist was a second, un-earned
auto-apply path parallel to heads. Both are retired — drop their storage.

(image_prediction = Camie's per-image predictions; tag_allowlist = the bulk-
apply allowlist. Nothing references INTO these tables, so the drop is clean.)

Revision ID: 0067
Revises: 0066
Create Date: 2026-06-30
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0067"
down_revision: Union[str, None] = "0066"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.drop_table("image_prediction")
    op.drop_table("tag_allowlist")


def downgrade() -> None:
    op.create_table(
        "tag_allowlist",
        sa.Column("tag_id", sa.Integer(), nullable=False),
        sa.Column(
            "min_confidence", sa.Float(), nullable=False, server_default="0.9"
        ),
        sa.Column(
            "created_at", sa.DateTime(timezone=True),
            server_default=sa.func.now(), nullable=False,
        ),
        sa.ForeignKeyConstraint(["tag_id"], ["tag.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("tag_id"),
        sa.CheckConstraint(
            "min_confidence >= 0 AND min_confidence <= 1",
            name="ck_tag_allowlist_confidence_range",
        ),
    )
    op.create_table(
        "image_prediction",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("image_record_id", sa.Integer(), nullable=False),
        sa.Column("raw_name", sa.String(length=255), nullable=False),
        sa.Column("category", sa.String(length=32), nullable=False),
        sa.Column("score", sa.Float(), nullable=False),
        sa.ForeignKeyConstraint(
            ["image_record_id"], ["image_record.id"], ondelete="CASCADE"
        ),
    )
    op.create_index(
        "ix_image_prediction_image", "image_prediction", ["image_record_id"]
    )
    op.create_index(
        "ix_image_prediction_name_score", "image_prediction",
        ["raw_name", "score"],
    )
