mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
Three additive migrations the v1.18.1 feature surfaces build on: reminder engine fields (endsOn + origin, so coach-cadence and preventive care produce into one reminder table), a user-scoped biomarker catalog (name, unit, bounds, optional encrypted context, panel) with a nullable LabResult.biomarkerId link, and the condition-journal model (IllnessEpisode plus a CycleDayLog-shaped symptom timeline). No code consumes these yet; the surfaces ship gated behind the module system.
48 lines
2.2 KiB
SQL
48 lines
2.2 KiB
SQL
-- v1.19.0 — reminder-engine fields for the "one engine" unification.
|
|
--
|
|
-- Two additive columns on `measurement_reminders` so the AI coach can
|
|
-- produce cadence reminders into the SAME table the Vorsorge surface uses
|
|
-- (one model, one recurrence helper, one cron, one create endpoint — not a
|
|
-- second "coach reminder" table):
|
|
--
|
|
-- * `ends_on` (nullable timestamp) — an optional course-window end. NULL =
|
|
-- open-ended cadence (the existing behaviour, every current row). Non-NULL
|
|
-- bounds a finite cadence so a Coach "measure BP morning+evening for a
|
|
-- week" self-expires: the recurrence engine stops producing occurrences
|
|
-- past this instant (the `medication.ends_on` precedent the engine already
|
|
-- supports).
|
|
--
|
|
-- * `origin` (enum `reminder_origin`, default `VORSORGE`) — provenance.
|
|
-- `VORSORGE` = the user created it through the Vorsorge surface (the
|
|
-- existing behaviour; backfilled onto every current row by the column
|
|
-- default). `COACH` = the coach minted it from an evidence-based cadence
|
|
-- suggestion. Lets the UI label provenance and lets Coach dedupe its own
|
|
-- suggestions.
|
|
--
|
|
-- No backfill needed: `ends_on` defaults NULL (open-ended) and `origin`
|
|
-- defaults `VORSORGE`, so every existing reminder keeps its current
|
|
-- behaviour. No new index — the cron already rides `(user_id, next_due_at)`
|
|
-- and these two columns are read alongside the row, never scanned on.
|
|
--
|
|
-- Idempotent guards (`IF NOT EXISTS` / `DO $$`) so reruns are safe on prod.
|
|
--
|
|
-- Reversibility (down):
|
|
-- ALTER TABLE "measurement_reminders" DROP COLUMN IF EXISTS "origin";
|
|
-- ALTER TABLE "measurement_reminders" DROP COLUMN IF EXISTS "ends_on";
|
|
-- DROP TYPE IF EXISTS "reminder_origin";
|
|
-- A roll-back loses the coach/vorsorge distinction + any course-window end
|
|
-- (every reminder falls back to open-ended user-created), which is the safe
|
|
-- default — no data is destroyed.
|
|
|
|
-- CreateEnum
|
|
DO $$ BEGIN
|
|
CREATE TYPE "reminder_origin" AS ENUM ('VORSORGE', 'COACH');
|
|
EXCEPTION
|
|
WHEN duplicate_object THEN null;
|
|
END $$;
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "measurement_reminders"
|
|
ADD COLUMN IF NOT EXISTS "ends_on" TIMESTAMP(3),
|
|
ADD COLUMN IF NOT EXISTS "origin" "reminder_origin" NOT NULL DEFAULT 'VORSORGE';
|