Back to Roadmap

Health & Sleep Data Schema

Add the health data tables from SYNTHESIS §7. Split from #16 (Extended Health Data Sync) — this is the schema work, #16 is the sync implementation.

Tables

  • sleep_sessions — discrete sleep events with summary scores (sleep_score, efficiency, stage durations, avg HRV, avg resting HR, avg SpO2)
  • sleep_streams — Parquet pointers for HR, sleep_stage, SpO2, respiratory_rate during sleep
  • health_samples_staging — Postgres buffer for incremental all-day samples (HR, steps, stress, skin temp). Rows deleted after daily compaction to Parquet.
  • health_streams — Parquet pointers for compacted daily health data
  • athlete_metrics — daily summary values: HRV, resting HR, weight, body fat, steps, stress, readiness, VO2max, sleep score, subjective wellness (soreness, fatigue, mood, motivation), training load metrics (CTL, ATL, TSB, ACWR), thresholds (FTP, max HR, LTHR, threshold pace)

Data flow examples (from SYNTHESIS §7)

  1. Whoop sleep webhooksleep_session + sleep_streams (Parquet) → athlete_metrics rows (sleep_score, hrv, readiness)
  2. Apple Health synchealth_samples_staging → daily compaction → health_streams (Parquet) → derive resting_hr/steps totals → athlete_metrics
  3. Manual weight entry → direct insert into athlete_metrics with source = 'manual'
  4. Oura readiness → direct insert into athlete_metrics (no raw samples needed)

Query patterns

  • Today's data (real-time): read from health_samples_staging (Postgres, fast)
  • Historical data (charts): read from health_streams Parquet files (S3, cheap)
  • Daily summary (calendar, coaching): read from athlete_metrics (Postgres, pre-computed)

Depends on

Schema Migration, Object Storage Setup

Blocks

#16, #25

Reference

See docs/api-research/SYNTHESIS.md §7 (Athlete Health Data: Three First-Class Entities).

Status
Backlog
Priority
Normal
Platform
API
Date
1 month ago