From 0e34f9eddaf2596b625ca3c4a43b7b74fb72e6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 10 Aug 2026 06:43:40 +0200 Subject: [PATCH] feat(medications): add per-schedule units-per-dose column Add a nullable units_per_dose to medication_schedules so a split-dose plan can consume a different unit count at different times of day (a whole tablet in the morning, a half at noon) on ONE medication instead of two. NULL inherits the medication-level units_per_dose, so every existing row keeps its current behaviour. Migration 0332 adds one nullable Decimal(10,4) column with no backfill. --- .../0332_schedule_units_per_dose/migration.sql | 6 ++++++ prisma/schema.prisma | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 prisma/migrations/0332_schedule_units_per_dose/migration.sql diff --git a/prisma/migrations/0332_schedule_units_per_dose/migration.sql b/prisma/migrations/0332_schedule_units_per_dose/migration.sql new file mode 100644 index 000000000..0dabcd0ae --- /dev/null +++ b/prisma/migrations/0332_schedule_units_per_dose/migration.sql @@ -0,0 +1,6 @@ +-- #219 — per-schedule inventory units consumed per dose. +-- Additive, nullable, no backfill: every existing schedule row reads NULL and +-- the consume hook keeps inheriting the medication-level `units_per_dose`, so +-- behaviour is unchanged until a user sets a per-slot value. Same +-- Decimal(10,4) grain as `medications.units_per_dose`. +ALTER TABLE "medication_schedules" ADD COLUMN "units_per_dose" DECIMAL(10,4); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3c1597a60..6b3692997 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -2738,6 +2738,16 @@ model MedicationSchedule { windowEnd String @map("window_end") // HH:mm format, e.g. "10:00" label String? // e.g. "Morning", "Evening" dose String? // Per-schedule dose override; null = use Medication.dose + /// v1.37.10 (#219) — per-schedule inventory units consumed per dose. The + /// intake consumption hook counts UNITS (tablets, ampoules, puffs); a + /// split-dose plan takes a different unit count at different times of day + /// (a whole tablet in the morning, a half at noon). NULL inherits the + /// medication-level `Medication.unitsPerDose`, so every existing row keeps + /// its current behaviour. Same Decimal(10,4) grain + curated fraction / + /// whole-number posture as the medication-level column; the consume hook + /// matches a taken intake's slot to its schedule by wall-clock time and + /// reads this first, falling back to the medication level on NULL. + unitsPerDose Decimal? @map("units_per_dose") @db.Decimal(10, 4) /// Legacy string encoding of the cadence ("null | 1,3,5 | i2;1,3,5"). /// v1.5 writes go to `rrule` / `rollingIntervalDays` and v1.5.1 flipped /// the readers to consult the new fields first.