DeviceHealthData table
The DeviceHealthData table in the FitStack - V2 schema has 19 columns, with 1 foreign key to Users.
Raw per-sample health data from Apple Health / Health Connect. Highest-volume table in the product. **COMPOSITE PK `(Id, DateFrom)`** — the PK carries a time component so the table can be range-partitioned. Any FK to this table would need both columns; nothing references it, and nothing should. A coach reading this needs an active grant carrying an `activity.*` or `sleep.*` scope, and the query must be clamped to `Date >= now() - HistoryWindowDays`.
Columns (19)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | not null | |
| DateFrom | timestamp with time zone | not null | |
| UserId | character varying(450) | not null, references Users.Id | CASCADE. |
| DataType | character varying(100) | not null | `HealthDataType`, ~66 SCREAMING_SNAKE members, stored as its string name. |
| Value | numeric(18,4) | not null | |
| Unit | character varying(50) | not null | |
| Date | date | not null | |
| DateTo | timestamp with time zone | not null | |
| SourceName | character varying(200) | ||
| SourceId | character varying(200) | ||
| Platform | integer | not null | `HealthPlatformType`. |
| ExternalUuid | character varying(200) | Dedupe key from the source platform. | |
| IsSynced | boolean | not null | |
| Metadata | jsonb | Typed payload per DataType — WorkoutMetadata, SleepMetadata, BloodPressureMetadata, etc. Serialized C# classes, no tables of their own. | |
| Notes | character varying(1000) | ||
| CreatedAt | timestamp with time zone | not null | |
| ModifiedAt | timestamp with time zone | ||
| IsDeleted | boolean | not null | |
| DeletedAt | timestamp with time zone |
Indexes (4)
(UserId, DateFrom)(IX_device_health_data_user_datefrom)(UserId, DataType, Date)(IX_device_health_data_user_type_date)(ExternalUuid)(IX_device_health_data_external_uuid)(IsSynced)(IX_device_health_data_is_synced)
Relationships
DeviceHealthData.UserIdreferencesUsers.Id