fix(api): AIN-141 migration use soft-delete for FK safety#23
Conversation
The previous 0011 migration (text() fix) used hard DELETE which raised ForeignKeyViolationError on prod when DELETE deepseek-r1-novita conflicted with inferences_model_id_fkey on historical inferences rows. Per Charter v3 §'audit log is append-only': historical inference rows must NOT be destroyed to clean the catalog. Switch to soft-delete: UPDATE models SET active=FALSE WHERE slug=:slug. Routing service skips inactive models, so functionally equivalent for new traffic while preserving FK integrity + audit history. Same pattern already used in scripts/fix_aamc_canon.py:99. Downgrade flips active back to TRUE (rather than no-op) so the migration is reversible; use with caution. Co-Authored-By: Claude <noreply@anthropic.com>
AIN-141 [Audit P1 · api] Strip retired AAMC models (`Llama-3.3-70B`, `DeepSeek R1`) from tests + scripts + migration
Phase 1 audit finding (2026-05-18). Retired AAMC v1.0 models still in active Status: code-side scope ✅ shipped (PR #19 merged, CI green); DB-side surfaced as founder DDL tap (migration drafted, awaiting founder review + apply). Code-side cleanup (✅ DONE, PR #19, merged to main)3 files, 12 insertions, 10 deletions:
CI conclusion: success. Pre-commit hooks all green (ruff + mypy --strict + pytest -x unit + smoke). DB-side cleanup (🛑 FOUNDER TAP REQUIRED, migration drafted locally)Local file: Migration targets 3 retired slugs for DELETE from
Per memory Why founder tap: Charter v3 §"Founder taps" lists "Supabase or Railway DDL" as founder-only. Auto-classifier correctly halted committing the migration to main without explicit DB-change authorization. Founder reviews the migration text + commits in a separate PR + runs Founder next action: cd ~/code/ainfera-ai/api
# 1. Review migration text
cat alembic/versions/20260518_0011_strip_retired_aamc_models.py
# 2. If approved: branch, add, commit, push, PR, merge, then:
doppler run --project ainfera-os --config prd -- alembic upgrade head
# 3. Verify deletion count matches expectation (likely 1-3 rows total)RefsPR #19 (code-side, merged): #19 |
Previous 0011 migration hit FK violation on prod (deepseek-r1-novita referenced by inferences). Switches to soft-delete (UPDATE active=FALSE) per Charter §audit-append-only + same pattern as fix_aamc_canon.py. Reversible downgrade.