From 5eeedd7202147887fc080ddc5e9ef6465dd69db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 14 May 2026 19:50:35 +0200 Subject: [PATCH] feat(db): add user.researchMode acknowledgment fields for GLP-1 PK chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three columns gate the opt-in GLP-1 PK research-view chart behind an undismissable MDR-disclaimer dialog (research §2.3, §11): research_mode_enabled — master switch, default false. research_mode_acknowledged_at — timestamp of the latest ack. research_mode_acknowledged_version — copy version the user read. Versioning the acknowledgment lets the Settings UI re-prompt when the disclaimer copy drifts ahead of the persisted value, so a copy update cannot quietly keep the chart visible to a user who has not read the new wording. Migration 0058 uses ADD COLUMN IF NOT EXISTS to mirror 0057's idempotent posture. --- .../0058_user_research_mode/migration.sql | 35 +++++++++++++++++++ prisma/schema.prisma | 22 ++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 prisma/migrations/0058_user_research_mode/migration.sql diff --git a/prisma/migrations/0058_user_research_mode/migration.sql b/prisma/migrations/0058_user_research_mode/migration.sql new file mode 100644 index 000000000..b4740e9ef --- /dev/null +++ b/prisma/migrations/0058_user_research_mode/migration.sql @@ -0,0 +1,35 @@ +-- v1.4.25 W19c — Research Mode acknowledgment fields. +-- +-- Adds three columns to the `users` table that together gate the +-- opt-in GLP-1 PK research-view chart behind an undismissable +-- MDR-disclaimer dialog (research §2.3 + §11). The chart never +-- renders unless `research_mode_enabled = true`, and the dialog +-- only flips that flag after the user explicitly acknowledges the +-- disclaimer copy at a specific version. +-- +-- research_mode_enabled — master on/off switch. +-- Default `false` keeps the +-- chart hidden for every +-- existing user. +-- research_mode_acknowledged_at — timestamp of the most +-- recent acknowledgment. +-- NULL when the user has +-- never acknowledged. +-- research_mode_acknowledged_version — string identifier of the +-- disclaimer copy version +-- the user acknowledged +-- (e.g. "2026-05-14.1"). The +-- Settings UI re-prompts when +-- the version drifts ahead +-- of the persisted value, so +-- copy updates cannot quietly +-- keep the chart visible. +-- +-- The `IF NOT EXISTS` guards make the migration idempotent — if any +-- column landed via a prior dev-DB hand-edit, the migration still +-- runs cleanly to completion (mirrors the 0057 onboarding-step +-- migration's posture). +ALTER TABLE "users" + ADD COLUMN IF NOT EXISTS "research_mode_enabled" BOOLEAN NOT NULL DEFAULT false, + ADD COLUMN IF NOT EXISTS "research_mode_acknowledged_at" TIMESTAMP(3), + ADD COLUMN IF NOT EXISTS "research_mode_acknowledged_version" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d729e5b78..547bc3e9c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -159,6 +159,28 @@ model User { // work. sourcePriorityJson Json? @map("source_priority_json") + // v1.4.25 W19c — Research Mode acknowledgment for the opt-in GLP-1 + // PK research-view chart. The chart is hidden behind a per-user + // flag that is set to `true` only after the user has dismissed an + // undismissable MDR-disclaimer dialog. The `researchModeAcknowledged*` + // pair records exactly *which version* of the disclaimer copy the + // user has read; when the disclaimer copy changes (e.g. EMA guidance + // update, new drug added), the Settings surface re-prompts the user + // and refuses to surface the chart until the new version is + // acknowledged. Keeping the version on the user row (instead of an + // append-only audit table) is intentional — the Coach refusal layer + // and the chart-render guard both need a cheap synchronous read. + // + // `researchModeEnabled = false` is the safe default — the chart + // never renders without an explicit opt-in. The DELETE branch of + // the API endpoint sets all three columns back to NULL/false so a + // user who turns Research Mode off must re-acknowledge the + // disclaimer if they ever turn it back on, even if the version + // hasn't changed in the interim. + researchModeEnabled Boolean @default(false) @map("research_mode_enabled") + researchModeAcknowledgedAt DateTime? @map("research_mode_acknowledged_at") + researchModeAcknowledgedVersion String? @map("research_mode_acknowledged_version") + // v1.4.25 W6c — Doctor-report section toggles. // Shape: // { "bp": boolean,