-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
142 lines (131 loc) · 3.98 KB
/
schema.sql
File metadata and controls
142 lines (131 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
-- xoop schema — Whoop data mirror (API v2)
-- run in Supabase SQL editor
-- High-resolution heart rate samples from Whoop data export
create table if not exists whoop_hr_sample (
ts timestamptz primary key,
bpm int not null,
source text default 'export'
);
create index if not exists whoop_hr_sample_ts_idx on whoop_hr_sample (ts);
-- Journal entries from Whoop app (behaviors logged each morning)
create table if not exists whoop_journal (
id text primary key,
day date not null,
question text not null,
answer text,
raw jsonb,
imported_at timestamptz default now()
);
create index if not exists whoop_journal_day_idx on whoop_journal (day);
create index if not exists whoop_journal_question_idx on whoop_journal (question);
-- Generic landing zone for unknown CSVs from imports
create table if not exists whoop_import_raw (
id uuid primary key default gen_random_uuid(),
filename text not null,
row_index int not null,
row jsonb not null,
imported_at timestamptz default now()
);
create index if not exists whoop_import_raw_filename_idx on whoop_import_raw (filename);
create table if not exists whoop_annotation (
id uuid primary key default gen_random_uuid(),
day date not null,
tag text not null,
value numeric,
note text,
created_at timestamptz default now()
);
create index if not exists whoop_annotation_day_idx on whoop_annotation (day);
create index if not exists whoop_annotation_tag_idx on whoop_annotation (tag);
create table if not exists whoop_tokens (
id text primary key,
access_token text not null,
refresh_token text not null,
expires_at timestamptz not null,
updated_at timestamptz default now()
);
create table if not exists whoop_profile (
user_id text primary key,
email text,
first_name text,
last_name text,
height_meter numeric,
weight_kilogram numeric,
max_heart_rate int,
updated_at timestamptz default now()
);
create table if not exists whoop_cycle (
id text primary key,
user_id text not null,
start_ts timestamptz not null,
end_ts timestamptz,
timezone_offset text,
score_state text,
strain numeric,
kilojoule numeric,
average_heart_rate int,
max_heart_rate int,
raw jsonb not null,
synced_at timestamptz default now()
);
create table if not exists whoop_recovery (
cycle_id text primary key,
user_id text not null,
sleep_id text,
created_at_ts timestamptz,
score_state text,
user_calibrating boolean,
recovery_score numeric,
resting_heart_rate int,
hrv_rmssd_milli numeric,
spo2_percentage numeric,
skin_temp_celsius numeric,
raw jsonb not null,
synced_at timestamptz default now()
);
create table if not exists whoop_sleep (
id text primary key,
user_id text not null,
start_ts timestamptz not null,
end_ts timestamptz,
nap boolean,
score_state text,
sleep_performance_percentage numeric,
sleep_consistency_percentage numeric,
sleep_efficiency_percentage numeric,
total_in_bed_milli bigint,
total_awake_milli bigint,
total_light_sleep_milli bigint,
total_slow_wave_sleep_milli bigint,
total_rem_sleep_milli bigint,
disturbance_count int,
respiratory_rate numeric,
raw jsonb not null,
synced_at timestamptz default now()
);
create table if not exists whoop_workout (
id text primary key,
user_id text not null,
start_ts timestamptz not null,
end_ts timestamptz,
sport_id int,
score_state text,
strain numeric,
average_heart_rate int,
max_heart_rate int,
kilojoule numeric,
distance_meter numeric,
altitude_gain_meter numeric,
altitude_change_meter numeric,
zone_zero_milli bigint,
zone_one_milli bigint,
zone_two_milli bigint,
zone_three_milli bigint,
zone_four_milli bigint,
zone_five_milli bigint,
raw jsonb not null,
synced_at timestamptz default now()
);
create index if not exists whoop_cycle_start_idx on whoop_cycle (user_id, start_ts desc);
create index if not exists whoop_sleep_start_idx on whoop_sleep (user_id, start_ts desc);
create index if not exists whoop_workout_start_idx on whoop_workout (user_id, start_ts desc);