feat(oura): capture daily resilience as an ordinal RESILIENCE metric

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.
This commit is contained in:
Marc-André Bombeck committed 2026-06-21 10:44:15 +02:00
1 parent 3faafef0df
commit aff4e9abeb
21 files changed
+338 -24

No files matched your search

@@ -0,0 +1,25 @@
-- 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';
+11
View File
@@ -905,6 +905,17 @@ enum MeasurementType {
// absolute-reading buckets. Plausible band is small and centred on 0.
BODY_TEMPERATURE_DEVIATION // celsius (signed deviation) — Oura `daily_readiness.temperature_deviation`.
// ── v1.19.0 — Oura resilience (additive) ──
// Oura's daily resilience level from the `daily_resilience` collection — a
// categorical band describing how well the body is coping with cumulative
// load: limited / adequate / solid / strong / exceptional. Stored ORDINAL-
// ENCODED into the numeric `value` (limited=1, adequate=2, solid=3, strong=4,
// exceptional=5) so it fits the existing numeric Measurement model with no new
// categorical column or CHECK constraint. Unit is the level scale (`level`).
// The 5-level → ordinal mapping is the single source of truth in
// `src/lib/oura/client.ts` (RESILIENCE_LEVELS). Stored as `source = OURA`.
RESILIENCE // level (ordinal 1–5) — Oura `daily_resilience.level` (limited=1 … exceptional=5).
@@map("measurement_type")
}