mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
feat: lay down the shared v1.42 contract
Land every file the v1.42 work shares before any of it is built, so the parts built side by side never edit the same file. Schema and migrations 0379-0386: the HEALTH_CONNECT measurement source, ImportJob.kind, the air-quality columns and the per-user switch on the environment tables, sealed environment locations with nullable plaintext, managed-profile handover links, the per-type HealthKit arrival ledger, lab unit-conversion provenance, and user-defined vaccines. Every new column is annotated for the column-reader sweep. HEALTH_CONNECT reaches every exhaustive list: the source labels, the read enum (not the write allowlist), the source-priority ladder cap, now the number of sources rather than a fixed eight, and the write-path smoke test. RMSSD gets its own priority class and a 300 ms ceiling. The batch syncTrigger gains `manual`, with its label on the Apple Health card. Queues for the Health Connect import, the compaction-tombstone purge and the measurement-table maintenance are registered with stub handlers; host-metric sampling moves to every five minutes. Environment and work_mem variables reach the compose whitelist, the production example and the manifest. The proxy admits the handover link and redirects it at the edge, and the Health Connect upload bypasses the proxy body limit. The new routes answer 501 behind their final authentication and are published in the contract; backup, wipe and key rotation classify the new models and columns; the seven message bundles carry the base copy. Guards that list release-pending keys and columns fail once an entry is wired, so those lists empty themselves before the tag. Also re-anchor a login-throttle fixture to the wall clock, where its expiry is compared, and re-base the aggregate bundle cap on a measured 12 KB of new locale strings.
This commit is contained in:
1 parent
125b15bfb7
commit
e63be67b5a
82 files changed
+5099
-727
No files matched your search
@@ -0,0 +1,14 @@
|
||||
-- Android Health Connect import provenance (#972).
|
||||
--
|
||||
-- Rows written by the Health Connect import worker carry their own
|
||||
-- `MeasurementSource` value, so they stay distinguishable from the Apple
|
||||
-- Health and generic IMPORT rows and get an isolated idempotency namespace
|
||||
-- `(userId, type, HEALTH_CONNECT, externalId)`.
|
||||
--
|
||||
-- Purely additive enum extension, alone in its migration: Postgres forbids
|
||||
-- USING a freshly added value in the same transaction, and nothing here uses
|
||||
-- it. `ADD VALUE IF NOT EXISTS` makes a rerun safe. Mirrors 0346 (EXTERNAL).
|
||||
--
|
||||
-- Reversibility: Postgres cannot remove an enum value, so `HEALTH_CONNECT`
|
||||
-- stays (inert with no rows).
|
||||
ALTER TYPE "measurement_source" ADD VALUE IF NOT EXISTS 'HEALTH_CONNECT';
|
||||
@@ -0,0 +1,9 @@
|
||||
-- Which importer owns an `import_jobs` row (#972).
|
||||
--
|
||||
-- Until now every row was an Apple Health export; the Health Connect importer
|
||||
-- shares the table. The reconcile cron and the staged-file sweep scope by
|
||||
-- `kind` so one importer never fails or deletes the other's running job.
|
||||
-- Every existing row is an Apple Health job, which the default records.
|
||||
ALTER TABLE "import_jobs" ADD COLUMN "kind" TEXT NOT NULL DEFAULT 'apple_health';
|
||||
|
||||
CREATE INDEX "import_jobs_user_id_kind_started_at_idx" ON "import_jobs"("user_id", "kind", "started_at");
|
||||
@@ -0,0 +1,40 @@
|
||||
-- Air quality, pollen and UV per environment day (#615).
|
||||
--
|
||||
-- Twenty-two nullable columns filled from the Open-Meteo air-quality feed
|
||||
-- (CAMS Europe / global). Nullable throughout: a partial feed stores what it
|
||||
-- has, and a day the feed never covered stays NULL rather than zero.
|
||||
-- `aq_fetched_at` NULL marks a day whose air-quality part has not been
|
||||
-- fetched yet; the partial gap index serves the nightly fill's lookup.
|
||||
--
|
||||
-- `users.environment_air_quality_enabled` is the per-user switch, on by
|
||||
-- default; the operator switch `ENVIRONMENT_AIR_QUALITY_DISABLED` wins.
|
||||
ALTER TABLE "environment_contexts"
|
||||
ADD COLUMN "apparent_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pm25_mean" DOUBLE PRECISION,
|
||||
ADD COLUMN "pm25_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pm10_mean" DOUBLE PRECISION,
|
||||
ADD COLUMN "no2_mean" DOUBLE PRECISION,
|
||||
ADD COLUMN "so2_mean" DOUBLE PRECISION,
|
||||
ADD COLUMN "co_mean" DOUBLE PRECISION,
|
||||
ADD COLUMN "o3_max_8h" DOUBLE PRECISION,
|
||||
ADD COLUMN "eaqi_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "usaqi_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "uv_index_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "dust_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "aod_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pollen_alder_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pollen_birch_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pollen_grass_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pollen_mugwort_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pollen_olive_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "pollen_ragweed_max" DOUBLE PRECISION,
|
||||
ADD COLUMN "aq_domain" TEXT,
|
||||
ADD COLUMN "aq_hours" INTEGER,
|
||||
ADD COLUMN "aq_fetched_at" TIMESTAMP(3);
|
||||
|
||||
CREATE INDEX "environment_contexts_aq_gap_idx"
|
||||
ON "environment_contexts"("user_id", "date")
|
||||
WHERE "aq_fetched_at" IS NULL;
|
||||
|
||||
ALTER TABLE "users"
|
||||
ADD COLUMN "environment_air_quality_enabled" BOOLEAN NOT NULL DEFAULT true;
|
||||
@@ -0,0 +1,36 @@
|
||||
-- Environment locations sealed at rest (#615).
|
||||
--
|
||||
-- The home location, each dated location period and the per-day resolved
|
||||
-- location gain a sealed copy (lat, lon, label under AAD
|
||||
-- `healthlog/environment-location/v1`). The free-text encryption backfill
|
||||
-- fills it from the plaintext and then clears the plaintext; the plaintext
|
||||
-- columns therefore become nullable here and drop in a later release, once
|
||||
-- the backfill reports zero remaining rows everywhere.
|
||||
--
|
||||
-- The partial indexes serve the backfill's discovery ("rows still holding
|
||||
-- plaintext") and empty themselves as it runs.
|
||||
ALTER TABLE "users" ADD COLUMN "home_location_encrypted" BYTEA;
|
||||
|
||||
ALTER TABLE "environment_travel_locations"
|
||||
ADD COLUMN "location_encrypted" BYTEA,
|
||||
ALTER COLUMN "lat" DROP NOT NULL,
|
||||
ALTER COLUMN "lon" DROP NOT NULL,
|
||||
ALTER COLUMN "label" DROP NOT NULL;
|
||||
|
||||
ALTER TABLE "environment_contexts"
|
||||
ADD COLUMN "location_encrypted" BYTEA,
|
||||
ALTER COLUMN "lat" DROP NOT NULL,
|
||||
ALTER COLUMN "lon" DROP NOT NULL,
|
||||
ALTER COLUMN "location_label" DROP NOT NULL;
|
||||
|
||||
CREATE INDEX "users_home_location_plain_idx"
|
||||
ON "users"("id")
|
||||
WHERE "home_lat" IS NOT NULL;
|
||||
|
||||
CREATE INDEX "environment_travel_locations_plain_location_idx"
|
||||
ON "environment_travel_locations"("id")
|
||||
WHERE "lat" IS NOT NULL;
|
||||
|
||||
CREATE INDEX "environment_contexts_plain_location_idx"
|
||||
ON "environment_contexts"("id")
|
||||
WHERE "lat" IS NOT NULL;
|
||||
@@ -0,0 +1,32 @@
|
||||
-- Managed profile handover links (#959).
|
||||
--
|
||||
-- A guardian mints a one-time link that hands a managed profile over to the
|
||||
-- person it describes. Only the HMAC-SHA256 hash of the token is stored.
|
||||
-- `proposals_json` carries the guardian-side proposal per guardian (end,
|
||||
-- read, manage) that the new owner confirms when claiming. The partial
|
||||
-- unique index allows at most one open (unused, unrevoked) link per profile.
|
||||
CREATE TABLE "managed_profile_handovers" (
|
||||
"id" TEXT NOT NULL,
|
||||
"profile_id" TEXT NOT NULL,
|
||||
"created_by_id" TEXT NOT NULL,
|
||||
"token_hash" TEXT NOT NULL,
|
||||
"proposals_json" JSONB NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"expires_at" TIMESTAMP(3) NOT NULL,
|
||||
"used_at" TIMESTAMP(3),
|
||||
"revoked_at" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "managed_profile_handovers_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX "managed_profile_handovers_token_hash_key" ON "managed_profile_handovers"("token_hash");
|
||||
|
||||
CREATE INDEX "managed_profile_handovers_profile_id_idx" ON "managed_profile_handovers"("profile_id");
|
||||
|
||||
CREATE UNIQUE INDEX "managed_profile_handovers_open_idx"
|
||||
ON "managed_profile_handovers"("profile_id")
|
||||
WHERE "used_at" IS NULL AND "revoked_at" IS NULL;
|
||||
|
||||
ALTER TABLE "managed_profile_handovers" ADD CONSTRAINT "managed_profile_handovers_profile_id_fkey" FOREIGN KEY ("profile_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "managed_profile_handovers" ADD CONSTRAINT "managed_profile_handovers_created_by_id_fkey" FOREIGN KEY ("created_by_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,16 @@
|
||||
-- Per-HealthKit-type arrival ledger (#1173).
|
||||
--
|
||||
-- One row per (user, type), upserted by the measurement batch route: when the
|
||||
-- type last arrived, under which `syncTrigger`, and when it last brought a new
|
||||
-- or updated sample. Diagnostic state the next sync rebuilds; not backed up.
|
||||
CREATE TABLE "healthkit_type_syncs" (
|
||||
"user_id" TEXT NOT NULL,
|
||||
"type" "measurement_type" NOT NULL,
|
||||
"last_received_at" TIMESTAMP(3) NOT NULL,
|
||||
"last_trigger" TEXT,
|
||||
"last_new_sample_at" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "healthkit_type_syncs_pkey" PRIMARY KEY ("user_id","type")
|
||||
);
|
||||
|
||||
ALTER TABLE "healthkit_type_syncs" ADD CONSTRAINT "healthkit_type_syncs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- Lab unit conversion provenance (#1095).
|
||||
--
|
||||
-- `biomarkers.analyte_key` names the catalogue analyte a marker resolves to,
|
||||
-- which selects its unit-conversion table. `lab_results.source_value` /
|
||||
-- `source_unit` keep the value and unit as printed on the report when a write
|
||||
-- converted the reading into the marker's canonical unit. All nullable; no
|
||||
-- existing row changes.
|
||||
ALTER TABLE "biomarkers" ADD COLUMN "analyte_key" TEXT;
|
||||
|
||||
ALTER TABLE "lab_results"
|
||||
ADD COLUMN "source_value" DOUBLE PRECISION,
|
||||
ADD COLUMN "source_unit" TEXT;
|
||||
@@ -0,0 +1,29 @@
|
||||
-- User-defined vaccines (#1005).
|
||||
--
|
||||
-- A vaccine the user defines for a product the shipped catalogue does not
|
||||
-- list, in the same shape a catalogue entry resolves to. A dose links to it
|
||||
-- through `vaccination_records.custom_vaccine_id`; deleting the definition
|
||||
-- sets the link to NULL and the dose stays on its `vaccine_name`.
|
||||
CREATE TABLE "custom_vaccines" (
|
||||
"id" TEXT NOT NULL,
|
||||
"user_id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"components" TEXT[],
|
||||
"typical_series_doses" INTEGER,
|
||||
"booster_interval_months" INTEGER,
|
||||
"deleted_at" TIMESTAMP(3),
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "custom_vaccines_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX "custom_vaccines_user_id_name_key" ON "custom_vaccines"("user_id", "name");
|
||||
|
||||
ALTER TABLE "custom_vaccines" ADD CONSTRAINT "custom_vaccines_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "vaccination_records" ADD COLUMN "custom_vaccine_id" TEXT;
|
||||
|
||||
CREATE INDEX "vaccination_records_custom_vaccine_id_idx" ON "vaccination_records"("custom_vaccine_id");
|
||||
|
||||
ALTER TABLE "vaccination_records" ADD CONSTRAINT "vaccination_records_custom_vaccine_id_fkey" FOREIGN KEY ("custom_vaccine_id") REFERENCES "custom_vaccines"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
+234
-34
@@ -64,9 +64,11 @@ model User {
|
||||
///
|
||||
/// A timestamp rather than a boolean: it says since when, and preserves a
|
||||
/// future-compatible null state without adding a transition surface here.
|
||||
/// This release does not expose a way to clear the marker or attach
|
||||
/// credentials; the grants and activity trail remain intact if a later,
|
||||
/// separately designed handover ever needs that state.
|
||||
/// Cleared by the handover flow (`ManagedProfileHandover`): when the
|
||||
/// person the profile describes claims it with credentials of their own,
|
||||
/// the marker goes back to null in the same transaction that settles the
|
||||
/// guardians' grants, so the account becomes an ordinary adult account.
|
||||
/// The grants and activity trail stay intact across that transition.
|
||||
///
|
||||
/// Consumers land in this release: the guardian resolver in
|
||||
/// `src/lib/api-handler.ts` reads it on every guardian request, and the
|
||||
@@ -91,16 +93,26 @@ model User {
|
||||
// without a home set) simply has no environment rows. `homeTimezone` anchors
|
||||
// the day-key an observation is stored under (it can differ from the display
|
||||
// `timezone` above for an account that tracks weather for another locale).
|
||||
homeLat Float? @map("home_lat")
|
||||
homeLon Float? @map("home_lon")
|
||||
homeLabel String? @map("home_label")
|
||||
homeTimezone String? @map("home_timezone")
|
||||
homeLat Float? @map("home_lat")
|
||||
homeLon Float? @map("home_lon")
|
||||
homeLabel String? @map("home_label")
|
||||
homeTimezone String? @map("home_timezone")
|
||||
// v1.25 — effective-from instant for the home location. Stamped the moment a
|
||||
// home is set/updated. Day resolution attributes a past day to home ONLY when
|
||||
// the day is on/after this instant; earlier days are skipped (never fabricated
|
||||
// from the current home). To fill the deep past the user adds an explicit
|
||||
// dated location period instead. Backfill defaults its start to this instant.
|
||||
homeSince DateTime? @map("home_since")
|
||||
homeSince DateTime? @map("home_since")
|
||||
/// @pending-consumer(#615) v1.42 — sealed home location (lat, lon, label)
|
||||
/// under AAD `healthlog/environment-location/v1`. Replaces the plaintext
|
||||
/// `homeLat` / `homeLon` / `homeLabel` once the free-text encryption backfill
|
||||
/// reports zero remaining rows; the plaintext columns drop in v1.43.
|
||||
homeLocationEncrypted Bytes? @map("home_location_encrypted")
|
||||
/// @pending-consumer(#615) v1.42 — per-user switch for the air-quality and
|
||||
/// pollen part of the environment module. On by default; off means the
|
||||
/// nightly fetch skips the air-quality feed and the surfaces leave the
|
||||
/// fields out. The operator switch `ENVIRONMENT_AIR_QUALITY_DISABLED` wins.
|
||||
environmentAirQualityEnabled Boolean @default(true) @map("environment_air_quality_enabled")
|
||||
|
||||
// Codex OAuth (ChatGPT subscription)
|
||||
codexAccessTokenEncrypted String? @map("codex_access_token_encrypted")
|
||||
@@ -971,6 +983,15 @@ model User {
|
||||
// `vaccinations` module key, which governs the surfaces and not the store.
|
||||
vaccinationRecords VaccinationRecord[]
|
||||
vaccinationDocumentLinks VaccinationDocumentLink[]
|
||||
// v1.42 — user-defined vaccines for products the shipped catalogue does
|
||||
// not list (#1005).
|
||||
customVaccines CustomVaccine[]
|
||||
// v1.42 — per-HealthKit-type arrival ledger (#1173).
|
||||
healthKitTypeSyncs HealthKitTypeSync[]
|
||||
// v1.42 — managed-profile handover links (#959): the profile being handed
|
||||
// over, and the guardian who minted the link.
|
||||
handoversOfProfile ManagedProfileHandover[] @relation("HandoverProfile")
|
||||
handoversCreated ManagedProfileHandover[] @relation("HandoverCreator")
|
||||
|
||||
// v1.7.0 profile — optional patient-identity fields surfaced on the
|
||||
// health-record export cover (PDF) and the FHIR `Patient` resource.
|
||||
@@ -1074,16 +1095,21 @@ model EnvironmentContext {
|
||||
date String
|
||||
|
||||
/// Coarse resolved location for the day (lat/lon rounded to 1 decimal, about
|
||||
/// 11 km, + label + the source that won precedence).
|
||||
lat Float
|
||||
lon Float
|
||||
/// 11 km, + label + the source that won precedence). Nullable since v1.42:
|
||||
/// the sealed copy in `locationEncrypted` replaces the plaintext once the
|
||||
/// encryption backfill has run; the plaintext columns drop in v1.43.
|
||||
lat Float?
|
||||
lon Float?
|
||||
/// @internal: human-readable label of the resolved location, stored as
|
||||
/// operator/debug provenance beside the coordinates; surfaces select the
|
||||
/// numeric and weather columns only, never this label. The backup selects it
|
||||
/// (`src/lib/export/environment-backup.ts`) with the rest of the row: a
|
||||
/// restored reading has to keep saying where it was read.
|
||||
locationLabel String @map("location_label")
|
||||
source EnvironmentLocationSource
|
||||
locationLabel String? @map("location_label")
|
||||
/// @pending-consumer(#615) v1.42 — sealed (lat, lon, label) for the day,
|
||||
/// AAD `healthlog/environment-location/v1`.
|
||||
locationEncrypted Bytes? @map("location_encrypted")
|
||||
source EnvironmentLocationSource
|
||||
|
||||
/// Daily temperature (°C). Min doubles as the overnight-low proxy.
|
||||
tempMin Float? @map("temp_min")
|
||||
@@ -1111,6 +1137,54 @@ model EnvironmentContext {
|
||||
/// WMO weather code for the day (descriptive condition lookup).
|
||||
weatherCode Int? @map("weather_code")
|
||||
|
||||
// v1.42 (#615) — air quality, pollen and UV from the Open-Meteo
|
||||
// air-quality feed (CAMS). All nullable: a partial or absent feed stores
|
||||
// what it has, and a day the feed never covered stays NULL, never zero.
|
||||
/// @pending-consumer(#615) Daily apparent ("feels-like") maximum (°C).
|
||||
apparentMax Float? @map("apparent_max")
|
||||
/// @pending-consumer(#615) PM2.5 daily mean (µg/m³).
|
||||
pm25Mean Float? @map("pm25_mean")
|
||||
/// @pending-consumer(#615) PM2.5 hourly maximum over the local day (µg/m³).
|
||||
pm25Max Float? @map("pm25_max")
|
||||
/// @pending-consumer(#615) PM10 daily mean (µg/m³).
|
||||
pm10Mean Float? @map("pm10_mean")
|
||||
/// @pending-consumer(#615) Nitrogen dioxide daily mean (µg/m³).
|
||||
no2Mean Float? @map("no2_mean")
|
||||
/// @pending-consumer(#615) Sulphur dioxide daily mean (µg/m³).
|
||||
so2Mean Float? @map("so2_mean")
|
||||
/// @pending-consumer(#615) Carbon monoxide daily mean (µg/m³).
|
||||
coMean Float? @map("co_mean")
|
||||
/// @pending-consumer(#615) Ozone, maximum 8-hour running mean of the day (µg/m³).
|
||||
o3Max8h Float? @map("o3_max_8h")
|
||||
/// @pending-consumer(#615) European AQI, daily maximum.
|
||||
eaqiMax Float? @map("eaqi_max")
|
||||
/// @pending-consumer(#615) US AQI, daily maximum.
|
||||
usaqiMax Float? @map("usaqi_max")
|
||||
/// @pending-consumer(#615) UV index, daily maximum.
|
||||
uvIndexMax Float? @map("uv_index_max")
|
||||
/// @pending-consumer(#615) Saharan dust, daily maximum (µg/m³).
|
||||
dustMax Float? @map("dust_max")
|
||||
/// @pending-consumer(#615) Aerosol optical depth, daily maximum.
|
||||
aodMax Float? @map("aod_max")
|
||||
/// @pending-consumer(#615) Alder pollen, daily maximum (grains/m³, Europe only).
|
||||
pollenAlderMax Float? @map("pollen_alder_max")
|
||||
/// @pending-consumer(#615) Birch pollen, daily maximum (grains/m³, Europe only).
|
||||
pollenBirchMax Float? @map("pollen_birch_max")
|
||||
/// @pending-consumer(#615) Grass pollen, daily maximum (grains/m³, Europe only).
|
||||
pollenGrassMax Float? @map("pollen_grass_max")
|
||||
/// @pending-consumer(#615) Mugwort pollen, daily maximum (grains/m³, Europe only).
|
||||
pollenMugwortMax Float? @map("pollen_mugwort_max")
|
||||
/// @pending-consumer(#615) Olive pollen, daily maximum (grains/m³, Europe only).
|
||||
pollenOliveMax Float? @map("pollen_olive_max")
|
||||
/// @pending-consumer(#615) Ragweed pollen, daily maximum (grains/m³, Europe only).
|
||||
pollenRagweedMax Float? @map("pollen_ragweed_max")
|
||||
/// @pending-consumer(#615) Which air-quality model domain served the day (`cams_europe` / `cams_global`).
|
||||
aqDomain String? @map("aq_domain")
|
||||
/// @pending-consumer(#615) Hourly air-quality samples the day was aggregated from (75 % rule).
|
||||
aqHours Int? @map("aq_hours")
|
||||
/// @pending-consumer(#615) When the air-quality part was last fetched; NULL = not yet fetched (gap index).
|
||||
aqFetchedAt DateTime? @map("aq_fetched_at")
|
||||
|
||||
/// When the row was last fetched/refreshed from the upstream feed.
|
||||
fetchedAt DateTime @default(now()) @map("fetched_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
@@ -1118,6 +1192,9 @@ model EnvironmentContext {
|
||||
|
||||
@@unique([userId, date])
|
||||
@@index([userId, date])
|
||||
// `environment_contexts_aq_gap_idx` (user_id, date) WHERE aq_fetched_at IS
|
||||
// NULL and `environment_contexts_plain_location_idx` (id) WHERE lat IS NOT
|
||||
// NULL are partial indexes from migrations 0381 / 0382 (raw SQL only).
|
||||
@@map("environment_contexts")
|
||||
}
|
||||
|
||||
@@ -1138,14 +1215,22 @@ model EnvironmentTravelLocation {
|
||||
startDate String @map("start_date")
|
||||
endDate String @map("end_date")
|
||||
|
||||
lat Float
|
||||
lon Float
|
||||
label String
|
||||
/// Plaintext coarse location. Nullable since v1.42: the sealed copy in
|
||||
/// `locationEncrypted` replaces it once the encryption backfill has run;
|
||||
/// the plaintext columns drop in v1.43.
|
||||
lat Float?
|
||||
lon Float?
|
||||
label String?
|
||||
/// @pending-consumer(#615) v1.42 — sealed (lat, lon, label) for the
|
||||
/// period, AAD `healthlog/environment-location/v1`.
|
||||
locationEncrypted Bytes? @map("location_encrypted")
|
||||
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([userId, startDate, endDate])
|
||||
// `environment_travel_locations_plain_location_idx` (id) WHERE lat IS NOT
|
||||
// NULL is a partial index from migration 0382 (raw SQL only).
|
||||
@@map("environment_travel_locations")
|
||||
}
|
||||
|
||||
@@ -1791,6 +1876,12 @@ enum MeasurementSource {
|
||||
// user's own. iOS DTO must mirror this exact spelling so the
|
||||
// /api/sync/changes delta feed decodes the rows.
|
||||
EXTERNAL
|
||||
// v1.42 — rows imported from an Android Health Connect export (#972).
|
||||
// Server-owned: written only by the Health Connect import worker, never
|
||||
// by a client, so the batch + single-POST surfaces reject it like IMPORT.
|
||||
// iOS DTO must mirror this spelling so the /api/sync/changes delta feed
|
||||
// decodes the rows.
|
||||
HEALTH_CONNECT
|
||||
|
||||
@@map("measurement_source")
|
||||
}
|
||||
@@ -3814,6 +3905,63 @@ model InviteToken {
|
||||
@@map("invite_tokens")
|
||||
}
|
||||
|
||||
/// v1.42 (#959) — a one-time link that hands a managed profile over to the
|
||||
/// person it describes. Minted by a guardian with MANAGE on the profile; the
|
||||
/// token (`hlp_` + 64 hex) is shown once and only its HMAC-SHA256 hash is
|
||||
/// stored, the `InviteToken` scheme. Claiming sets credentials on the
|
||||
/// profile's own `User` row (no data moves), clears `managedProfileAt` and
|
||||
/// settles each guardian's grant by the proposal recorded here. At most one
|
||||
/// open link per profile (partial unique index in migration 0383).
|
||||
model ManagedProfileHandover {
|
||||
id String @id @default(cuid())
|
||||
/// The managed profile (`User` row with `managedProfileAt` set).
|
||||
profileId String @map("profile_id")
|
||||
/// The guardian who minted the link.
|
||||
createdById String @map("created_by_id")
|
||||
/// @pending-consumer(#959) HMAC-SHA256 of the token, unique.
|
||||
tokenHash String @unique @map("token_hash")
|
||||
/// @pending-consumer(#959) Per-guardian proposal (end / read / manage) the
|
||||
/// new owner confirms or changes when claiming.
|
||||
proposalsJson Json @map("proposals_json")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
/// @pending-consumer(#959) Link expiry (1, 7 or 14 days after minting).
|
||||
expiresAt DateTime @map("expires_at")
|
||||
/// @pending-consumer(#959) Set when the profile was claimed through the link.
|
||||
usedAt DateTime? @map("used_at")
|
||||
/// @pending-consumer(#959) Set when a guardian withdrew the link.
|
||||
revokedAt DateTime? @map("revoked_at")
|
||||
|
||||
profile User @relation("HandoverProfile", fields: [profileId], references: [id], onDelete: Cascade)
|
||||
createdBy User @relation("HandoverCreator", fields: [createdById], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([profileId])
|
||||
// `managed_profile_handovers_open_idx` UNIQUE (profile_id) WHERE used_at IS
|
||||
// NULL AND revoked_at IS NULL is a partial index from migration 0383.
|
||||
@@map("managed_profile_handovers")
|
||||
}
|
||||
|
||||
/// v1.42 (#1173) — when each HealthKit type last arrived through the batch
|
||||
/// ingest, and by which trigger. One row per (user, type), upserted by the
|
||||
/// batch route; read by the Apple Health card's per-type freshness list.
|
||||
/// Diagnostic state: rebuilt by the next sync, so it is not backed up.
|
||||
model HealthKitTypeSync {
|
||||
userId String @map("user_id")
|
||||
type MeasurementType
|
||||
/// @pending-consumer(#1173) Last batch that carried this type.
|
||||
lastReceivedAt DateTime @map("last_received_at")
|
||||
/// @pending-consumer(#1173) `syncTrigger` of that batch
|
||||
/// (`foreground` / `background` / `push` / `manual`), NULL when absent.
|
||||
lastTrigger String? @map("last_trigger")
|
||||
/// @pending-consumer(#1173) Last batch that inserted or updated a sample of
|
||||
/// this type (as opposed to sending only duplicates).
|
||||
lastNewSampleAt DateTime? @map("last_new_sample_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([userId, type])
|
||||
@@map("healthkit_type_syncs")
|
||||
}
|
||||
|
||||
// v1.16.0 — one row per signup an invite admitted. `InviteToken.usedBy`
|
||||
// keeps only the LAST consumer (it overwrites on multi-use invites);
|
||||
// this ledger carries the full history so the admin table can show
|
||||
@@ -4958,8 +5106,8 @@ model AppSettings {
|
||||
// `src/lib/ai/reasoning/resolve.ts` and published per record on
|
||||
// `GET /api/auth/me` as `coachReasoning`. Defaults keep reasoning on with no
|
||||
// cap, so an upgrade needs no admin action.
|
||||
aiReasoningEnabled Boolean @default(true) @map("ai_reasoning_enabled")
|
||||
aiReasoningMaxEffort String @default("high") @map("ai_reasoning_max_effort")
|
||||
aiReasoningEnabled Boolean @default(true) @map("ai_reasoning_enabled")
|
||||
aiReasoningMaxEffort String @default("high") @map("ai_reasoning_max_effort")
|
||||
|
||||
// v1.18.0 — operator-level server-wide module availability. A DISABLED
|
||||
// allowlist mirroring the per-user `User.modulePreferencesJson`: absent /
|
||||
@@ -5439,6 +5587,11 @@ model ImportJob {
|
||||
pgBossJobId String? @unique @map("pg_boss_job_id")
|
||||
/// `queued | unpacking | parsing | upserting | done | failed`.
|
||||
status String @default("queued")
|
||||
/// @pending-consumer(#972) v1.42 — which importer owns the row:
|
||||
/// `apple_health` (every row before v1.42) or `health_connect`. The
|
||||
/// reconcile cron and the staged-file sweep scope by it so one importer
|
||||
/// never fails or deletes the other's running job.
|
||||
kind String @default("apple_health")
|
||||
/// Free-text reason on `failed`; null otherwise.
|
||||
failureReason String? @map("failure_reason")
|
||||
/// Bytes uploaded — surfaced to the operator audit trail.
|
||||
@@ -5486,6 +5639,7 @@ model ImportJob {
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId, startedAt])
|
||||
@@index([userId, kind, startedAt])
|
||||
@@index([status])
|
||||
@@map("import_jobs")
|
||||
}
|
||||
@@ -5929,6 +6083,13 @@ model LabResult {
|
||||
sourceReferenceLow Float? @map("source_reference_low")
|
||||
sourceReferenceHigh Float? @map("source_reference_high")
|
||||
sourceReferenceText String? @map("source_reference_text")
|
||||
/// @pending-consumer(#1095) v1.42 — the value as printed on the source
|
||||
/// report, kept when a write converted it into the biomarker's canonical
|
||||
/// unit. NULL when no conversion happened. A later edit of `value` clears it.
|
||||
sourceValue Float? @map("source_value")
|
||||
/// @pending-consumer(#1095) v1.42 — the unit the source report printed,
|
||||
/// paired with `sourceValue`.
|
||||
sourceUnit String? @map("source_unit")
|
||||
/// When the sample was taken (UTC instant; wall-clock anchoring is the
|
||||
/// reader's concern per the schema's UTC-only convention).
|
||||
takenAt DateTime @map("taken_at")
|
||||
@@ -5997,6 +6158,10 @@ model Biomarker {
|
||||
/// and from the lab-entry pickers, but never deleted — its readings and
|
||||
/// canonical unit/range definition survive.
|
||||
hidden Boolean @default(false) @map("hidden")
|
||||
/// @pending-consumer(#1095) v1.42 — the catalogue analyte this marker
|
||||
/// resolves to (alias list in `src/lib/labs/biomarker-catalog.ts`), which
|
||||
/// selects the unit-conversion table. NULL = not resolved; no conversion.
|
||||
analyteKey String? @map("analyte_key")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@ -9120,13 +9285,13 @@ model EncounterConditionLink {
|
||||
/// module is off; these data routes stay exempt so a restore or an import
|
||||
/// keeps working and re-enabling finds every row intact.
|
||||
model VaccinationRecord {
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
/// The day the dose was given, at UTC midnight. An Impfpass carries dates,
|
||||
/// never times, so the time component is not meaningful and is not
|
||||
/// collected. The API refuses future instants: a vaccination is logged
|
||||
/// after the fact, and a planned booster is a reminder, not a record.
|
||||
occurredAt DateTime @map("occurred_at")
|
||||
occurredAt DateTime @map("occurred_at")
|
||||
/// Catalogue identity. NULL = a free-text-only row, which is the arm that
|
||||
/// makes a 1987 Pass line loggable at all.
|
||||
///
|
||||
@@ -9136,48 +9301,83 @@ model VaccinationRecord {
|
||||
/// resolve, but a restore writes whatever the backup held. A slug that
|
||||
/// stops resolving degrades to the free-text arm — a tested behaviour, not
|
||||
/// an accident (`src/lib/vaccinations/__tests__/catalog-integrity.test.ts`).
|
||||
antigenSlug String? @map("antigen_slug")
|
||||
antigenSlug String? @map("antigen_slug")
|
||||
/// The Pass's own wording, verbatim. May be a trade name; that is user
|
||||
/// data. Plaintext and bounded so the list can render and search it.
|
||||
vaccineName String? @map("vaccine_name")
|
||||
vaccineName String? @map("vaccine_name")
|
||||
/// The Pass's claim about which dose this is. Optional — the series
|
||||
/// derivation falls back to the chronological index per component antigen.
|
||||
doseNumber Int? @map("dose_number")
|
||||
doseNumber Int? @map("dose_number")
|
||||
/// Per-record override of the catalogue's typical series length, for the
|
||||
/// schedule a person was actually given.
|
||||
seriesDoses Int? @map("series_doses")
|
||||
seriesDoses Int? @map("series_doses")
|
||||
/// Chargenbezeichnung (IfSG §22). A batch code, not a secret: plaintext and
|
||||
/// bounded so the list and the report can render it without a decrypt.
|
||||
lotNumber String? @map("lot_number")
|
||||
site VaccinationSite?
|
||||
practitionerId String? @map("practitioner_id")
|
||||
encounterId String? @map("encounter_id")
|
||||
lotNumber String? @map("lot_number")
|
||||
site VaccinationSite?
|
||||
practitionerId String? @map("practitioner_id")
|
||||
encounterId String? @map("encounter_id")
|
||||
/// The booster reminder this dose satisfied, when one matched. The act runs
|
||||
/// through `satisfyReminder`; this column is the record of it, not the act.
|
||||
/// One id for possibly several satisfied rows — the engine keeps
|
||||
/// `lastSatisfiedAt` per reminder, this keeps the first match in catalogue
|
||||
/// component order.
|
||||
reminderId String? @map("reminder_id")
|
||||
reminderId String? @map("reminder_id")
|
||||
/// @pending-consumer(#1005) v1.42 — the user's own vaccine definition when
|
||||
/// the dose is for a product the catalogue does not list. Catalogue wins
|
||||
/// when both resolve. SetNull on delete: the dose keeps its `vaccineName`.
|
||||
customVaccineId String? @map("custom_vaccine_id")
|
||||
/// The one free-text field (AES-256-GCM at rest, the `*Encrypted` Bytes
|
||||
/// convention). Impfreaktionen live here in v1 rather than in a structured
|
||||
/// reaction model nobody has asked for yet.
|
||||
noteEncrypted Bytes? @map("note_encrypted")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
noteEncrypted Bytes? @map("note_encrypted")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
/// Soft-delete tombstone. NULL = live; non-NULL = deleted at the instant.
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
practitioner Practitioner? @relation(fields: [practitionerId], references: [id], onDelete: SetNull)
|
||||
encounter Encounter? @relation(fields: [encounterId], references: [id], onDelete: SetNull)
|
||||
reminder MeasurementReminder? @relation(fields: [reminderId], references: [id], onDelete: SetNull)
|
||||
customVaccine CustomVaccine? @relation(fields: [customVaccineId], references: [id], onDelete: SetNull)
|
||||
documentLinks VaccinationDocumentLink[]
|
||||
|
||||
@@index([userId, deletedAt, occurredAt])
|
||||
@@index([userId, antigenSlug, occurredAt])
|
||||
@@index([customVaccineId])
|
||||
@@map("vaccination_records")
|
||||
}
|
||||
|
||||
/// v1.42 (#1005) — a vaccine the user defines for a product the shipped
|
||||
/// catalogue does not list. Same shape the resolver hands out for a
|
||||
/// catalogue entry (`components` = antigen slugs, typical series length,
|
||||
/// booster interval), so series derivation and booster matching treat both
|
||||
/// alike. Soft-deleted; a deleted definition leaves its doses standing on
|
||||
/// their `vaccineName`.
|
||||
model CustomVaccine {
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
/// @pending-consumer(#1005) Display name, unique per user.
|
||||
name String
|
||||
/// @pending-consumer(#1005) Antigen slugs the product covers.
|
||||
components String[]
|
||||
/// @pending-consumer(#1005) Typical primary-series length.
|
||||
typicalSeriesDoses Int? @map("typical_series_doses")
|
||||
/// @pending-consumer(#1005) Booster interval in months; NULL = no booster.
|
||||
boosterIntervalMonths Int? @map("booster_interval_months")
|
||||
/// Soft-delete tombstone. NULL = live.
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
records VaccinationRecord[]
|
||||
|
||||
@@unique([userId, name])
|
||||
@@map("custom_vaccines")
|
||||
}
|
||||
|
||||
/// Where the dose went. Small and closed, because the Pass's own vocabulary
|
||||
/// is small and closed; OTHER absorbs the rest rather than growing the enum.
|
||||
enum VaccinationSite {
|
||||
|
||||
Reference in new issue
Block a user