mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
Oura's daily_resilience collection reports a categorical level — limited, adequate, solid, strong, exceptional. Encode it ordinally (limited=1 … exceptional=5) into the numeric measurement value so it fits the existing model with no new categorical column: add the RESILIENCE measurement type (migration 0186), fetch and map daily_resilience in the Oura sync, and skip an unknown or missing level rather than coercing it to zero. RESILIENCE_LEVELS in the Oura client is the single source of truth for the encoding. The day-keyed externalId keeps a re-sync idempotent so a re-scored day overwrites in place. Extend the measurement-type label, unit, range, category, chart-token, and PR-direction maps; add the metric label across all six locales.
26 lines
1.2 KiB
SQL
26 lines
1.2 KiB
SQL
-- v1.19.0 — Oura resilience capture (additive).
|
|
--
|
|
-- One new `measurement_type` enum value, `RESILIENCE`, so the Oura sync can
|
|
-- store the daily resilience level from the `daily_resilience` collection.
|
|
--
|
|
-- Oura exposes resilience as a categorical band — limited / adequate / solid /
|
|
-- strong / exceptional — describing how well the body copes with cumulative
|
|
-- load. Rather than introduce a new categorical column + CHECK constraint, the
|
|
-- level is ORDINAL-ENCODED into the existing numeric `value`:
|
|
--
|
|
-- limited = 1, adequate = 2, solid = 3, strong = 4, exceptional = 5
|
|
--
|
|
-- The 5-level → ordinal mapping is the single source of truth in
|
|
-- `src/lib/oura/client.ts` (RESILIENCE_LEVELS). Unit is the level scale
|
|
-- (`level`). Stored as `source = OURA`. An unknown / missing level string mints
|
|
-- no row (it is skipped, never coerced to 0).
|
|
--
|
|
-- Purely-additive: one enum extension, no backfill, no existing row touched, no
|
|
-- new table or column. Idempotent guard (`IF NOT EXISTS`) so reruns are safe on
|
|
-- prod.
|
|
--
|
|
-- Reversibility (down): Postgres cannot drop a single enum value in place; the
|
|
-- value is inert until a row references it, so a down migration is a no-op.
|
|
|
|
ALTER TYPE "measurement_type" ADD VALUE IF NOT EXISTS 'RESILIENCE';
|