mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 14:16:12 +00:00
medication_compliance_rollups lost its last reader when compliance moved to the schedule-anchored computation, yet every dose write still upserted it, a boot backfill refolded it, and the wipe and backup plans carried it. The per-dose hook keeps the one derived row that still hangs off a dose day, the supplement nutrients, under dose-day-refresh. The pending-row mints (today projection, reminder) no longer call it, since an untaken dose adds no nutrients. The import job finishes without its per-day recompute phase; its progress keeps touchedDays and rollupProcessed on the wire, inert and documented as deprecated. The backfill queue is retired on boot and migration 0414 drops the table under a bounded lock wait.
33 lines
1.4 KiB
SQL
33 lines
1.4 KiB
SQL
-- Drop `medication_compliance_rollups`.
|
|
--
|
|
-- The per-(user, medication, day) coverage ledger lost its last reader when
|
|
-- the dashboard tile and the compliance views moved to the schedule-anchored
|
|
-- computation; every dose write still upserted a row into it, a boot backfill
|
|
-- refolded it, and it travelled through the data wipe for nothing. The write
|
|
-- hook now refreshes only what still derives from a dose day (the supplement
|
|
-- nutrients), and the boot retires the backfill queue.
|
|
--
|
|
-- Nothing is lost: the table held counts derived from
|
|
-- `medication_intake_events`, which stay.
|
|
--
|
|
-- Lock wait. Dropping the table removes its two foreign keys, and removing a
|
|
-- foreign key's triggers takes ACCESS EXCLUSIVE on the referenced tables,
|
|
-- `users` and `medications`, for the instant the catalog changes. Waiting for
|
|
-- that lock behind a long reader would queue every login and every
|
|
-- medication read behind the migration, so the wait is bounded at five
|
|
-- seconds inside one `DO` block (one statement, so it commits or rolls back
|
|
-- whole; `migrate deploy` runs a file statement by statement). A lock
|
|
-- timeout changes nothing and the file is safe to apply again, which the
|
|
-- marker declares (docs/ops/deploy.md, "A migration that timed out on a
|
|
-- lock").
|
|
--
|
|
-- @retry-on-lock-timeout
|
|
|
|
DO $migration$
|
|
BEGIN
|
|
PERFORM set_config('lock_timeout', '5s', true);
|
|
|
|
DROP TABLE IF EXISTS "medication_compliance_rollups";
|
|
END
|
|
$migration$;
|