mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
The daily-mean consolidation and the dense hourly fold cut at `now - threshold` instead of a local day boundary. A day was folded in two runs and the second run overwrote the stored mean with the mean of the later part alone: every mean-type day, and the boundary hour of every heart-rate, HRV and SpO2 day, plus the derived resting figure and the DAY rollup of such a day. The Health Connect importer split its raw window at the same unaligned instant. - Fold up to the start of the account's local day the threshold ends in (`foldBoundary`), for every consolidation pass and the Health Connect importer's raw/hourly split. - A window that already has a live `stats:` row is refolded from every sample of it, live rows plus the fold's own tombstones; with none left the stored mean stays. - `folded_window` refuses a raw sample only when its local day lies before the aligned boundary and a live `stats:` row of its source covers it, also within reach of the sample after a timezone change. - A deletion inside a day the fold had not finished is class B. - Add a one-time, resumable fold repair per account that recomputes each hourly and daily mean from its remaining samples and writes only values that differ, recorded in `measurement_fold_repairs` (migration 0389). - The compaction-tombstone purge waits for the repair per account, and the boot sends no purge run before one account is repaired. - The restore keys live `stats:` ids by source, and writes compaction tombstones back from a file older than the account's repair, resetting the repair.
prisma/
The database layer. HealthLog runs PostgreSQL 16 via Prisma 7. This directory holds the single schema file and the forward-only migration history; the generated client is emitted elsewhere.
Contents
schema.prisma— 61 models, one file.cuid()primary keys,snake_casecolumns via@map(...), encrypted columns mostly suffixed*Encrypted(search the file; there are 24 encrypted column references). Thegenerator clientblock emits to../src/generated/prisma(imported as@/generated/prisma).migrations/— numbered, forward-only SQL migrations (0001_…upward).migration_lock.tomlpins the provider topostgresql.
Migration workflow
# author a migration from a schema edit
pnpm dlx prisma migrate dev --name <short_snake_case_name>
# regenerate the client after any schema change
pnpm dlx prisma generate
Number a new migration with the next free prefix. The production entrypoint runs prisma migrate deploy on boot, so every migration must apply cleanly forward — there is no down-migration path. Always include the migration file in the same change as the schema edit.
Conventions
- Encryption is fail-closed:
*Encryptedcolumns are written through@/lib/crypto(AES-256-GCM, versioned key ids); never store plaintext in an encrypted column. Key rotation isscripts/rotate-encryption-key.ts+docs/ops/encryption-key-rotation.md. - The generated client under
src/generated/prismais build output — do not edit it. - Schema-touching changes that affect the API surface must regenerate
docs/api/openapi.yaml(see../CLAUDE.md).
Related: ../src/lib/README.md (db.ts, rollups/), ../docs/ops/ (migrations + backup runbooks).