"""translation strictness setting + per-post translation override (milestone 155)

ImportSettings gains ``translation_min_confidence`` (the latin-script acceptance
floor, now operator-tunable in the UI; default 0.9 — stricter than the old
hardcoded 0.8, since Interpreter confidently mis-detects short ASCII English at
~0.86). Post gains ``translation_override`` — a sticky per-post choice of
auto / force / original so the operator can force a skipped translation on, or
knock a wrongly-translated one back to the original, and have it survive a
Re-translate-all.

Revision ID: 0084
Revises: 0083
Create Date: 2026-07-10
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0084"
down_revision: Union[str, None] = "0083"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "import_settings",
        sa.Column(
            "translation_min_confidence", sa.Float(), nullable=False,
            server_default=sa.text("0.9"),
        ),
    )
    op.add_column(
        "post",
        sa.Column(
            "translation_override", sa.String(16), nullable=False,
            server_default="auto",
        ),
    )
    op.create_check_constraint(
        "ck_post_translation_override",
        "post",
        "translation_override IN ('auto', 'force', 'original')",
    )


def downgrade() -> None:
    op.drop_constraint("ck_post_translation_override", "post", type_="check")
    op.drop_column("post", "translation_override")
    op.drop_column("import_settings", "translation_min_confidence")
