Files
HealthLog/prisma/migrations/0343_ai_capability_switches/migration.sql
T
Marc-André Bombeck a7888a9011 feat(ai): replace the Correlations switch with Reading documents
The operator switches become master, Coach, Daily Briefing, Status
notes and Reading documents. Correlations goes: it gated statistics,
not anything a model writes. Reading documents covers the document
vault, lab scans and medication extraction.

The Coach module's operator availability now follows the Coach
switch, so there is one place to turn the Coach off server-wide. The
migration folds a stored Coach availability of false into the switch,
and gives everyone who hid the Coach the AI analysis opt-out, since
hiding the Coach no longer stops nightly briefing and status notes.

A switch read that fails now fails closed. The insights module is
described as AI analysis in every locale, and the switch guard now
keeps both retired switches out and freezes the callers of the old
operator-only gate.
2026-09-24 07:36:47 +02:00

44 lines
2.0 KiB
SQL

-- The assistant switches stop AI work instead of hiding surfaces, and AI stops
-- being able to take data down with it.
--
-- 1. A new "Reading documents" switch covers the document vault's AI reads,
-- lab report scans and medication text extraction, which only the master
-- covered before. Default on, like every other switch.
ALTER TABLE "app_settings"
ADD COLUMN IF NOT EXISTS "assistant_document_ai_enabled" BOOLEAN NOT NULL DEFAULT true;
-- 2. One operator Coach switch instead of two. Where the operator had turned
-- the Coach module off in module availability, the Coach switch takes that
-- answer; the availability key is then removed, since nothing reads it.
UPDATE "app_settings"
SET "assistant_coach_enabled" = false
WHERE jsonb_typeof("module_availability_json") = 'object'
AND "module_availability_json" -> 'coach' = 'false'::jsonb;
UPDATE "app_settings"
SET "module_availability_json" = "module_availability_json" - 'coach'
WHERE jsonb_typeof("module_availability_json") = 'object'
AND "module_availability_json" ? 'coach';
-- 3. "Hide Coach" means the Coach and nothing else from now on. It used to
-- stop the nightly briefing and status notes as well; that promise moves to
-- the AI analysis switch (the `insights` module), so everyone who hid the
-- Coach gets AI analysis switched off and keeps the privacy they chose.
-- `updated_at` moves so a settings form loaded before the upgrade cannot
-- write the old map back over this one.
UPDATE "users"
SET "module_preferences_json" =
CASE
WHEN jsonb_typeof("module_preferences_json") = 'object'
THEN "module_preferences_json" || '{"insights": false}'::jsonb
ELSE '{"insights": false}'::jsonb
END,
"updated_at" = now()
WHERE "disable_coach" = true;
-- 4. The Correlations switch gated statistics, not anything a model writes,
-- so it goes. Destructive by design: the setting is gone, and so is its
-- stored value.
ALTER TABLE "app_settings"
DROP COLUMN IF EXISTS "assistant_correlations_enabled";