fix(migration): make 0045 DDL-only; backfill image_prediction via batched task (#768) #95
Reference in New Issue
Block a user
Delete Branch "dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
The previous deploy wedged: web booted an image whose migration 0045 still ran an inline
INSERT…SELECTbackfill over the ~100 GBimage_record.tagger_predictionsTOAST. Because table creation + backfill were one transaction, nothing committed for ~1h44m, it was unmonitorable, and the earlier MATERIALIZED-CTE form spilled the full 100 GB to temp on NFS. (Compounded by Swarm's:latestre-pull trap —service update --image …:latestdidn't fetch the streaming build.)Change
Split the table creation from the data copy:
image_prediction+ indexes and commits instantly, so web boots in seconds regardless of library size.backend.app.tasks.admin.backfill_image_predictions_taskcopies the>=store-floor predictions from the JSON intoimage_prediction, walkingimage_recordin 2000-id windows with a boundedINSERT…SELECToverjson_each(CASE-guarded against scalar/null rows), committed per chunk: live progress, resumable (re-enqueues from the last committed id), idempotent (ON CONFLICT DO NOTHING).json_eachstays in the DB executor streaming each window — no Python-side 100 GB load, no materialization. Self-resumes on the 600 s chunk boundary / soft limit;maintenance_longlane.POST /api/admin/maintenance/backfill-predictions+ a Settings → Maintenance "Backfill predictions now" card to trigger the one-time run after upgrading.Deploy notes
docker pull …:latest+docker service update --force) — the:latesttag-string update alone won't fetch the new image.\d image_prediction.SELECT count(*) FROM image_predictionclimb.Step 3 of #768 (stop the JSON dual-write, drop
image_record.tagger_predictions,VACUUM FULLto reclaim ~100 GB, excludeimage_predictionfrom backups) stays HELD until the backfill + read cutover are verified in prod.Dev CI green (run 877: lint, backend pytest, integration, frontend-build all ✓).
🤖 Generated with Claude Code