Files
HealthLog/prisma/migrations/0331_emergency_profile/migration.sql
T
Marc-André Bombeck 9e52285acc feat(profile): add emergency profile storage
Fold six nullable columns into user_health_profiles: three closed-set
enums (blood type, organ-donor status, advance-directive status) read as
plaintext, and three AES-256-GCM free-text columns (emergency contacts,
implants, ICE note). Migration 0331 is additive only: three CREATE TYPE
plus one ALTER TABLE with nullable ADD COLUMNs. An integration test
asserts the columns and enum types exist on the migrated schema.
2026-08-10 05:32:58 +02:00

29 lines
1.3 KiB
SQL

-- Emergency ("Notfalldaten") facts on the health profile.
--
-- Additive only. No table is dropped or restructured: three new enum types and
-- six new nullable columns fold into the existing `user_health_profiles` row,
-- one row per user. The three enums are plaintext closed sets read directly by
-- the doctor-report emergency page (the same shape `User.gender` uses); the
-- three BYTEA columns hold AES-256-GCM ciphertext, fail-closed on read like
-- every other `*_encrypted` column. Every column is nullable, so an account
-- that never fills in an emergency profile carries six NULLs and nothing
-- surfaces.
-- CreateEnum
CREATE TYPE "emergency_blood_type" AS ENUM ('A_POS', 'A_NEG', 'B_POS', 'B_NEG', 'AB_POS', 'AB_NEG', 'O_POS', 'O_NEG', 'UNKNOWN');
-- CreateEnum
CREATE TYPE "organ_donor_status" AS ENUM ('YES', 'NO', 'UNKNOWN');
-- CreateEnum
CREATE TYPE "advance_directive_status" AS ENUM ('EXISTS', 'NONE', 'UNKNOWN');
-- AlterTable
ALTER TABLE "user_health_profiles"
ADD COLUMN "emergency_blood_type" "emergency_blood_type",
ADD COLUMN "organ_donor_status" "organ_donor_status",
ADD COLUMN "advance_directive_status" "advance_directive_status",
ADD COLUMN "emergency_contacts_encrypted" BYTEA,
ADD COLUMN "emergency_implants_encrypted" BYTEA,
ADD COLUMN "emergency_note_encrypted" BYTEA;