"""Drop the orphaned EV-gate activation settings.

``activation_min_expected_value`` and ``activation_min_target_probability`` are
leftovers from the June 2026 EV-gate redesign (migration 009). That gate was
superseded by the residual-momentum gate, and the current code reads neither key:
``admin_service._ACTIVATION_FLOAT_KEYS`` exposes only ``min_momentum_percentile``,
``min_rr`` and ``min_confidence``, and ``qualification.setup_qualifies`` gates on
those plus the hardcoded ``MIN_TARGET_PROBABILITY`` floor.

The rows are therefore inert but actively misleading: prod carries
``activation_min_target_probability = 50.0``, so anyone reading the DB (or an
Admin screen rendering it) would reasonably believe a 50% probability floor is
enforced. It is not — the real floor is the 20% constant in ``qualification.py``.

Reads never recreate them (``settings_store.get_value`` returns a default without
persisting), and the current Admin write path no longer emits these keys, so the
delete is permanent. Follows the precedent of migrations 009, 015 and 018.

Revision ID: 020
Revises: 019
Create Date: 2026-07-12 00:00:00.000000
"""

from __future__ import annotations

from alembic import op
import sqlalchemy as sa


revision = "020"
down_revision = "019"
branch_labels = None
depends_on = None


ORPHANED_KEYS = (
    "activation_min_expected_value",
    "activation_min_target_probability",
)


def upgrade() -> None:
    op.execute(
        sa.text(
            "DELETE FROM system_settings WHERE key IN "
            "('activation_min_expected_value', 'activation_min_target_probability')"
        )
    )


def downgrade() -> None:
    # Restore the values prod carried before the delete. They are inert either
    # way — no code path reads them — but this keeps the downgrade faithful.
    # ``updated_at`` is NOT NULL with only a Python-side default, so raw SQL must
    # supply it explicitly.
    op.execute(
        sa.text(
            "INSERT INTO system_settings (key, value, updated_at) VALUES "
            "('activation_min_expected_value', '0.01', CURRENT_TIMESTAMP), "
            "('activation_min_target_probability', '50.0', CURRENT_TIMESTAMP) "
            "ON CONFLICT (key) DO NOTHING"
        )
    )
