mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
The Withings Sleep v2 sync writes one Measurement row per stage segment (AWAKE | CORE | DEEP | REM) for the same night, all sharing the legacy four-column composite (user_id, type=SLEEP_DURATION, measured_at, source=WITHINGS). Migration 0055 adds sleep_stage as the fifth axis and recreates the unique index with NULLS NOT DISTINCT so non-sleep rows (sleep_stage IS NULL) still dedup on the first four columns — same effective semantics as before for every meastype other than SLEEP_DURATION. Prisma's generated compound input requires non-null fields, so the Withings sync's upsert is reshaped as findFirst + create/update for the non-sleep path (sleepStage is always NULL there). The new five-column upsert key is the canonical path for the Sleep v2 ingest landing in W17c.