mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
Twenty-one foreign keys with ON DELETE CASCADE or SET NULL had no index leading with their column, so deleting a parent scanned the child table once per row; medication_intake_events.medication_id was the one an account delete paid for. Seventeen small-table indexes and the measurements (user_id, type, measured_at) index repeated the leading columns of another index and only cost writes. Migration 0415 adds and drops the small-table ones in one DO block under a bounded lock wait; 0416 drops the measurements index concurrently, in a file of its own. An integration test holds the schema to both rules from the catalog, each with a counter-check, and compares the plans of the user-and-type query shapes on a seeded table with and without the dropped index. The lock-timeout guard now also requires a CONCURRENTLY statement to stand alone in its file.