mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
chore(release): v1.28.34 — nutrient intake lands as quiet context (server side)
Supplement-style intake written to Apple Health by nutrition apps — vitamins, minerals, water, caffeine — can now sync as daily totals into a dedicated NutrientIntakeDay store (migration 0241): composite (user, day, nutrient) identity, re-post replaces, no soft delete, no rollup coupling. A code-side catalog carries the 26 nutrient codes with canonical units, plausibility caps, and EFSA dietary reference values (direction-aware; chromium cites NIH ODS where EFSA declined a DRV). Deliberately not a nutrition feature: no diary, no calories, no dashboard surface. POST /api/nutrients/batch is gated behind the new opt-in nutrients module (default off — with the module off the server refuses ingest entirely), rate-limited, idempotency-wrapped, with per-entry unit-mismatch and out-of-range skips. GET /api/nutrients serves a catalog-ordered summary; the only visible surface is a read-only card under Settings → Sources. Coach/correlation access is a later slice; the iOS reading side is coordinated in the companion-app tracker.
This commit is contained in:
1 parent
14a9a08a6e
commit
5445fc67ea
34 files changed
+2766
-12
No files matched your search
@@ -0,0 +1,37 @@
|
||||
-- v1.28 — micronutrient intake daily totals (opt-in `nutrients` module).
|
||||
--
|
||||
-- One row per (user, local day, nutrient): vitamins, minerals, water and
|
||||
-- caffeine as supplement-style day totals synced from Apple Health. The
|
||||
-- composite PK is the idempotency key — an iOS re-post of a grown day
|
||||
-- total replaces the row in place (last-writer-wins day-total contract),
|
||||
-- so there is no externalId column and no soft delete. `day` is a
|
||||
-- YYYY-MM-DD TEXT key anchored to the user's IANA timezone (the
|
||||
-- EnvironmentContext / MedicationComplianceRollup day-key precedent);
|
||||
-- `nutrient` is a bare TEXT code enforced in code against the closed
|
||||
-- catalog (`src/lib/nutrients/catalog.ts`) so adding a code never needs
|
||||
-- a migration. `unit` is denormalised from the catalog on purpose: rows
|
||||
-- stay self-describing in exports even if the catalog ever drifts.
|
||||
CREATE TABLE "nutrient_intake_days" (
|
||||
"user_id" TEXT NOT NULL,
|
||||
"day" TEXT NOT NULL,
|
||||
"nutrient" TEXT NOT NULL,
|
||||
"amount" DOUBLE PRECISION NOT NULL,
|
||||
"unit" TEXT NOT NULL,
|
||||
"source" TEXT NOT NULL DEFAULT 'APPLE_HEALTH',
|
||||
"external_source_version" TEXT,
|
||||
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "nutrient_intake_days_pkey" PRIMARY KEY ("user_id", "day", "nutrient")
|
||||
);
|
||||
|
||||
-- Read path: the settings-card / read-endpoint window scan per user, and
|
||||
-- the later per-nutrient series fetch (day DESC for "latest first").
|
||||
CREATE INDEX "nutrient_intake_days_user_id_nutrient_day_idx"
|
||||
ON "nutrient_intake_days" ("user_id", "nutrient", "day" DESC);
|
||||
|
||||
-- Account deletion cascades; rows are worthless without their owner.
|
||||
ALTER TABLE "nutrient_intake_days"
|
||||
ADD CONSTRAINT "nutrient_intake_days_user_id_fkey"
|
||||
FOREIGN KEY ("user_id") REFERENCES "users"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -805,6 +805,10 @@ model User {
|
||||
// that win over the home location for the days they cover.
|
||||
environmentContexts EnvironmentContext[]
|
||||
environmentTravelLocations EnvironmentTravelLocation[]
|
||||
// v1.28 — micronutrient intake daily totals synced from Apple Health
|
||||
// (vitamins, minerals, water, caffeine). Opt-in `nutrients` module, off
|
||||
// by default; the ingest route refuses while the module is off.
|
||||
nutrientIntakeDays NutrientIntakeDay[]
|
||||
// v1.25 (W-DOCS-IN) — inbound clinical documents (doctor reports /
|
||||
// discharge letters) the user uploads. The raw document is encrypted at
|
||||
// rest; extracted facts land in a review-then-confirm staging area
|
||||
@@ -6201,3 +6205,43 @@ model DocumentThumbnail {
|
||||
@@index([userId])
|
||||
@@map("document_thumbnails")
|
||||
}
|
||||
|
||||
// ─── Nutrient intake (v1.28) ───────────────────────────────────────
|
||||
//
|
||||
// Micronutrient daily totals synced from Apple Health — vitamins,
|
||||
// minerals, water, caffeine as supplement-style "substances taken",
|
||||
// never a food diary (energy / macros are out of scope by directive).
|
||||
// One row per (user, local day, nutrient); the composite PK IS the
|
||||
// idempotency key, so an iOS re-post of a grown day total replaces the
|
||||
// row in place (last-writer-wins day-total contract — the `stats:`
|
||||
// overwrite semantics without externalId string parsing). `nutrient`
|
||||
// is a bare string enforced in code against the closed catalog in
|
||||
// `src/lib/nutrients/catalog.ts` (the IntegrationStatus precedent: no
|
||||
// migration to add a code). No soft delete: rows are source-owned day
|
||||
// totals; replace-on-repost is the correction mechanism and account
|
||||
// deletion cascades. Behind the opt-in `nutrients` module
|
||||
// (refuse-ingest-when-off).
|
||||
|
||||
model NutrientIntakeDay {
|
||||
userId String @map("user_id")
|
||||
/// YYYY-MM-DD anchored to the user's IANA timezone (iOS-computed —
|
||||
/// the same day-key contract as the `stats:` externalIds).
|
||||
day String
|
||||
/// Closed catalog code ("vitamin_d", "magnesium", "water", ...).
|
||||
nutrient String
|
||||
/// Daily total in the catalog's canonical unit.
|
||||
amount Float
|
||||
/// Canonical unit echoed from the catalog ("mg" | "ug" | "ml") —
|
||||
/// denormalised on purpose: rows stay self-describing in exports
|
||||
/// even if the catalog ever drifts.
|
||||
unit String
|
||||
source String @default("APPLE_HEALTH")
|
||||
externalSourceVersion String? @map("external_source_version")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([userId, day, nutrient])
|
||||
@@index([userId, nutrient, day(sort: Desc)])
|
||||
@@map("nutrient_intake_days")
|
||||
}
|
||||
Reference in new issue
Block a user