From 1c05bba56c1b866392a5f18dd6a744aca3f393b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 27 Jul 2026 14:14:31 +0200 Subject: [PATCH] docs(jobs): correct two migration citations and the import dedup contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The retention-purge comments still cite migration 0277 for indexes that landed in 0276 — the renumbering moved the directories and left the prose behind. The schema is trustworthy because its comments are, so a wrong number is not cosmetic. The import worker's `already_recorded` reason claimed the skip covers a dose recorded on any other intake surface. It does not: `source` is part of the live-row unique, so a hand-logged dose and an imported one at the same slot are different keys and both are written. Say what the mechanism actually does, and say plainly that cross-surface dedup is not there. --- src/lib/jobs/audit-log-cleanup.ts | 2 +- src/lib/jobs/measurement-tombstone-cleanup.ts | 2 +- src/lib/jobs/medication-intake-import.ts | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/jobs/audit-log-cleanup.ts b/src/lib/jobs/audit-log-cleanup.ts index d4294805f..b79ba31b3 100644 --- a/src/lib/jobs/audit-log-cleanup.ts +++ b/src/lib/jobs/audit-log-cleanup.ts @@ -37,7 +37,7 @@ export function getAuditLogRetentionDays(): number { * on every removed row. Past the 60-second `statement_timeout` that aborts and * rolls back, and the next night repeats it against the same rows — a * retention window that can never close on an instance that has accumulated - * enough of them. Migration 0277 adds the `created_at` index; the batching + * enough of them. Migration 0276 adds the `created_at` index; the batching * keeps any single statement bounded regardless. */ export async function cleanupOldAuditLogs( diff --git a/src/lib/jobs/measurement-tombstone-cleanup.ts b/src/lib/jobs/measurement-tombstone-cleanup.ts index 9431320c6..43c2f5db5 100644 --- a/src/lib/jobs/measurement-tombstone-cleanup.ts +++ b/src/lib/jobs/measurement-tombstone-cleanup.ts @@ -38,7 +38,7 @@ function tombstoneCutoff(now: Date): Date { * the transaction rolled back, and the next night ran the identical statement * against the same rows. `measurements` is the densest table in the schema and * a bulk source delete can tombstone a six-figure row count in one action, so - * this is the one most likely to have been stuck. Migration 0277 adds the + * this is the one most likely to have been stuck. Migration 0276 adds the * partial index the predicate needs. */ export async function cleanupExpiredMeasurementTombstones( diff --git a/src/lib/jobs/medication-intake-import.ts b/src/lib/jobs/medication-intake-import.ts index 2fa7f0228..2d0a365e9 100644 --- a/src/lib/jobs/medication-intake-import.ts +++ b/src/lib/jobs/medication-intake-import.ts @@ -58,8 +58,13 @@ export interface MedicationImportPayload { * * `duplicate_in_file` — two rows of the same submission resolve to the same * medication and slot, so only one can be written. - * `already_recorded` — the dose is already on the ledger for that slot, from an - * earlier import or from any other intake surface. + * `already_recorded` — the dose is already on the ledger for that slot from an + * earlier import. `source` is part of the live-row unique + * `(user_id, medication_id, scheduled_for, source)`, so this does NOT cover a + * dose the person logged by hand at the same slot on another surface: that row + * and the imported one are distinct keys and both are written. Cross-surface + * dedup is a slot-window question, not a unique-key one, and it does not exist + * yet — do not read this reason as though it did. * * Those two used to be one `skippedDuplicates` number, which is how a file whose * every row collapsed onto one key could report "27 duplicates skipped" about 27