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)

Columns of the DeviceHealthData table
ColumnTypeConstraintsDescription
Iduuidnot null
DateFromtimestamp with time zonenot null
UserIdcharacter varying(450)not null, references Users.IdCASCADE.
DataTypecharacter varying(100)not null`HealthDataType`, ~66 SCREAMING_SNAKE members, stored as its string name.
Valuenumeric(18,4)not null
Unitcharacter varying(50)not null
Datedatenot null
DateTotimestamp with time zonenot null
SourceNamecharacter varying(200)
SourceIdcharacter varying(200)
Platformintegernot null`HealthPlatformType`.
ExternalUuidcharacter varying(200)Dedupe key from the source platform.
IsSyncedbooleannot null
MetadatajsonbTyped payload per DataType — WorkoutMetadata, SleepMetadata, BloodPressureMetadata, etc. Serialized C# classes, no tables of their own.
Notescharacter varying(1000)
CreatedAttimestamp with time zonenot null
ModifiedAttimestamp with time zone
IsDeletedbooleannot null
DeletedAttimestamp 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.UserId references Users.Id