CoachDataAccessLogs table

The CoachDataAccessLogs table in the FitStack - V2 schema has 15 columns, keyed by Id, with 4 foreign keys to Coaches, Users, CoachAccessGrants and DataScopes.

**Append-only.** No audit columns, no updates, no deletes — the row IS the record. This is what lets a client be shown "your coach opened your weight history 4 times last week", and what makes an over-broad grant detectable instead of theoretical. v1 had nothing here: client meal and workout logs were pushed to coaches with no trace that it ever happened. Operationally: high write volume. Partition by month on `AccessedAt` and set a retention policy (24 months is a defensible default) before this becomes the largest table in the database.

Columns (15)

Columns of the CoachDataAccessLogs table
ColumnTypeConstraintsDescription
Iduuidprimary key, not null
AccessedAttimestamp with time zonenot null
CoachIduuidnot null, references Coaches.IdRESTRICT — the log outlives everything else.
ClientIdtextnot null, references Users.Id
AccessGrantIduuidreferences CoachAccessGrants.IdNull when the outcome was DeniedNoGrant.
DataScopeIduuidreferences DataScopes.IdThe scope demanded by the endpoint.
Operationtextnot null`DataAccessOperation`.
Outcometextnot null`DataAccessOutcome`.
ResourceTypecharacter varying(100)e.g. "DeviceHealthData", "MealLog".
RecordCountintegerRows returned. Makes a bulk scrape visible next to a normal page view.
RangeFromdateDate window actually served, after history-window clamping.
RangeTodate
Endpointcharacter varying(200)Route that served it.
CorrelationIduuidTies this to the request trace in Sentry.
IpAddresscharacter varying(45)

Indexes (4)

  • (ClientId, AccessedAt) (IX_CoachDataAccessLogs_ClientId_AccessedAt)
  • (CoachId, AccessedAt) (IX_CoachDataAccessLogs_CoachId_AccessedAt)
  • (Outcome, AccessedAt) (IX_CoachDataAccessLogs_Outcome_AccessedAt)
  • (AccessGrantId) (IX_CoachDataAccessLogs_AccessGrantId)

Relationships