mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
Migrations 0402 to 0410: AI usage levels, biomarker aliases and merges, medication ingredients (with the supplement label run kind), life circumstance fact kinds, AI sections and AUDIT-C, Dawarich context, the pulse day-mean method, intraday hour buckets, the readable location drop and five relation link tables. Every new column carries its reader or a pending-consumer marker. 0409 refuses to run while any home, location period or stored day still holds a readable location, and names the counts. Locations are read from the sealed copy only; the encryption backfill no longer handles them, and the demo seed writes sealed locations only. The new tables are backed up and wiped, the new sealed columns are in the rotation registry with labels of their own, the AI usage level and the life-circumstance confirmations travel with the backup, and the wellbeing score reads the mental-health screeners only.
51 lines
2.0 KiB
SQL
51 lines
2.0 KiB
SQL
-- Drop the plaintext location columns (#615 follow-up).
|
|
--
|
|
-- Since v1.42 every location is sealed (`users.home_location_encrypted`,
|
|
-- `environment_contexts.location_encrypted`,
|
|
-- `environment_travel_locations.location_encrypted`), and the free-text
|
|
-- encryption backfill moved the plaintext into the sealed copy and cleared
|
|
-- it. This migration removes the plaintext columns and the partial indexes
|
|
-- from 0382 that served the backfill.
|
|
--
|
|
-- It refuses to run while any row still holds a plaintext location: such a
|
|
-- row has not been sealed yet, and dropping the column would lose it. Start
|
|
-- the previous release, let the backfill finish (the three counts below must
|
|
-- all be 0), then upgrade again.
|
|
DO $$
|
|
DECLARE
|
|
home_rows BIGINT;
|
|
travel_rows BIGINT;
|
|
day_rows BIGINT;
|
|
BEGIN
|
|
SELECT count(*) INTO home_rows FROM "users" WHERE "home_lat" IS NOT NULL;
|
|
SELECT count(*) INTO travel_rows FROM "environment_travel_locations" WHERE "lat" IS NOT NULL;
|
|
SELECT count(*) INTO day_rows FROM "environment_contexts" WHERE "lat" IS NOT NULL;
|
|
IF home_rows > 0 OR travel_rows > 0 OR day_rows > 0 THEN
|
|
RAISE EXCEPTION 'HealthLog migration 0409 stopped: % home location(s), % location period(s) and % daily location(s) are still stored in plaintext. Run the previous release until its free-text encryption backfill reports zero remaining rows, then upgrade again. Nothing was changed.', home_rows, travel_rows, day_rows;
|
|
END IF;
|
|
END
|
|
$$;
|
|
|
|
-- DropIndex
|
|
DROP INDEX IF EXISTS "users_home_location_plain_idx";
|
|
DROP INDEX IF EXISTS "environment_travel_locations_plain_location_idx";
|
|
DROP INDEX IF EXISTS "environment_contexts_plain_location_idx";
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "users"
|
|
DROP COLUMN "home_lat",
|
|
DROP COLUMN "home_lon",
|
|
DROP COLUMN "home_label";
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "environment_contexts"
|
|
DROP COLUMN "lat",
|
|
DROP COLUMN "lon",
|
|
DROP COLUMN "location_label";
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "environment_travel_locations"
|
|
DROP COLUMN "lat",
|
|
DROP COLUMN "lon",
|
|
DROP COLUMN "label";
|