diff --git a/src/lib/jobs/offhost-backup.ts b/src/lib/jobs/offhost-backup.ts index 4cde9d472..0e117809b 100644 --- a/src/lib/jobs/offhost-backup.ts +++ b/src/lib/jobs/offhost-backup.ts @@ -216,6 +216,9 @@ export async function runOffhostBackup( try { const [measurements, medications, intakeEvents, moodEntries] = await Promise.all([ + // includes soft-deleted rows because this is the DR snapshot, + // not a user-facing export — see + // `/api/export/full-backup/route.ts` for the symmetric exclusion. prisma.measurement.findMany({ where: { userId: user.id } }), prisma.medication.findMany({ where: { userId: user.id }, diff --git a/src/lib/personal-records/pr-detection-worker.ts b/src/lib/personal-records/pr-detection-worker.ts index dacd05370..53bcaf85a 100644 --- a/src/lib/personal-records/pr-detection-worker.ts +++ b/src/lib/personal-records/pr-detection-worker.ts @@ -217,7 +217,7 @@ export async function detectPersonalRecordsForUser( // Warm-up gate. Cheap count first so we don't pull a 30k-row // scan on a brand-new account. const sampleCount = await prisma.measurement.count({ - where: { userId, type: metricType }, + where: { userId, type: metricType, deletedAt: null }, }); if (sampleCount < PR_DETECTION_WARMUP_THRESHOLD) continue; @@ -400,7 +400,7 @@ async function findBestMeasurement( direction: PersonalRecordDirection, ): Promise { const row = await prisma.measurement.findFirst({ - where: { userId, type }, + where: { userId, type, deletedAt: null }, orderBy: direction === PersonalRecordDirection.MAX ? { value: "desc" }