mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 14:32:03 +00:00
Carry per-drug reminder phase timings, and stop claiming the notification preferences could travel
Two entries sat side by side on the coverage register, described as "the same shape of loss". They are not the same shape at all, and the difference is worth writing down. ReminderPhaseConfig hangs off a medication, one row per drug, nested inside something that already travels. It needed nothing new and it travels now. The round trip tunes all four thresholds away from their defaults and puts one of them in PERCENT rather than MINUTES, because a restore that quietly fell back to the schema defaults would hand back four plausible numbers and change when the drug turns orange. NotificationPreference cannot travel, and the register was wrong to imply it was merely unbuilt. A preference addresses ONE notification channel by a hard foreign key. The channel model is deliberately excluded from every backup because it carries channel secrets, and the restore deletes every channel it finds. A carried preference would point at a row that cannot exist: the same constraint violation the custom mood categories were causing, waiting for somebody to implement it in good faith. So it moves to the deliberate exclusions with a reason that names the dependency instead of the symptom. Re-applying somebody's tuning to a channel they add after a restore is a feature about channel types, not a backup contract about rows, and it should be argued for on its own terms rather than smuggled in as debt repayment.
This commit is contained in:
1 parent
e56b54cf24
commit
16b10c7855
6 files changed
+147
-5
No files matched your search
@@ -191,6 +191,8 @@ const COUNT_BACK: Record<
|
||||
MoodTagCategory: (p, userId) =>
|
||||
p.moodTagCategory.count({ where: { userId } }),
|
||||
MoodTagHidden: (p, userId) => p.moodTagHidden.count({ where: { userId } }),
|
||||
ReminderPhaseConfig: (p, userId) =>
|
||||
p.reminderPhaseConfig.count({ where: { medication: { userId } } }),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -271,6 +273,23 @@ async function seedEveryTwoEndedModel(prisma: PrismaClient): Promise<void> {
|
||||
// one away without recording it. A restore that recomputed the count from
|
||||
// the ledger would "fix" that to 22 and disagree with every low-stock
|
||||
// reminder the account has already received.
|
||||
// Tuned away from every default, and one threshold in PERCENT rather than
|
||||
// MINUTES: a restore that fell back to the schema defaults would return four
|
||||
// plausible numbers and silently change when this drug turns orange.
|
||||
await prisma.reminderPhaseConfig.create({
|
||||
data: {
|
||||
medicationId: medication.id,
|
||||
greenValue: 45,
|
||||
greenMode: "MINUTES",
|
||||
yellowValue: 20,
|
||||
yellowMode: "PERCENT",
|
||||
orangeValue: 5,
|
||||
orangeMode: "MINUTES",
|
||||
redValue: 180,
|
||||
redMode: "MINUTES",
|
||||
},
|
||||
});
|
||||
|
||||
const openPack = await prisma.medicationInventoryItem.create({
|
||||
data: {
|
||||
userId: OWNER_ID,
|
||||
@@ -1123,6 +1142,22 @@ describe("every model the plan claims two-ended survives a real restore", () =>
|
||||
expect(hidden).toHaveLength(1);
|
||||
expect(hidden[0].moodTag.userId).toBeNull();
|
||||
|
||||
// Every threshold as tuned, including the one that is not in minutes.
|
||||
const phase = await prisma.reminderPhaseConfig.findFirstOrThrow({
|
||||
where: { medication: { userId: OWNER_ID } },
|
||||
});
|
||||
expect({
|
||||
green: [phase.greenValue, phase.greenMode],
|
||||
yellow: [phase.yellowValue, phase.yellowMode],
|
||||
orange: [phase.orangeValue, phase.orangeMode],
|
||||
red: [phase.redValue, phase.redMode],
|
||||
}).toEqual({
|
||||
green: [45, "MINUTES"],
|
||||
yellow: [20, "PERCENT"],
|
||||
orange: [5, "MINUTES"],
|
||||
red: [180, "MINUTES"],
|
||||
});
|
||||
|
||||
// The shelf, and the count that must not be recomputed.
|
||||
const packs = await prisma.medicationInventoryItem.findMany({
|
||||
where: { userId: OWNER_ID },
|
||||
|
||||
Reference in new issue
Block a user