mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
Migration 0073 adds a UNIQUE constraint on (user_id, medication_id, scheduled_for, source) for medication_intake_events. Pre-fix the table only had an INDEX on those three columns, so the two newly-projecting routes — the intake route (PR #191) and the dashboard summary route (v1.4.39.4) — could pass their existence probes simultaneously and mint the same REMINDER row twice when the iOS app hydrates both endpoints in parallel. `source` is in the key so the reminder worker's REMINDER row doesn't collide with manual user inserts (WEB / TELEGRAM / IMPORT) on the same slot — distinct intake sources at the same scheduled instant are a legitimate shape (Telegram-bot logged take + a Web-UI correction on the same dose). The legacy (user_id, medication_id, scheduled_for) index stays in place because most reads filter on those three columns without caring about source. The new constraint becomes the structural backstop; the createMany skipDuplicates: true flag added in the two routes is the defense-in-depth layer. Additive only. DO $$ … EXCEPTION-on-duplicate guard mirrors 0067 / 0071 so re-runs are idempotent.