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)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null | |
| AccessedAt | timestamp with time zone | not null | |
| CoachId | uuid | not null, references Coaches.Id | RESTRICT — the log outlives everything else. |
| ClientId | text | not null, references Users.Id | |
| AccessGrantId | uuid | references CoachAccessGrants.Id | Null when the outcome was DeniedNoGrant. |
| DataScopeId | uuid | references DataScopes.Id | The scope demanded by the endpoint. |
| Operation | text | not null | `DataAccessOperation`. |
| Outcome | text | not null | `DataAccessOutcome`. |
| ResourceType | character varying(100) | e.g. "DeviceHealthData", "MealLog". | |
| RecordCount | integer | Rows returned. Makes a bulk scrape visible next to a normal page view. | |
| RangeFrom | date | Date window actually served, after history-window clamping. | |
| RangeTo | date | ||
| Endpoint | character varying(200) | Route that served it. | |
| CorrelationId | uuid | Ties this to the request trace in Sentry. | |
| IpAddress | character 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
CoachDataAccessLogs.CoachIdreferencesCoaches.IdCoachDataAccessLogs.ClientIdreferencesUsers.IdCoachDataAccessLogs.AccessGrantIdreferencesCoachAccessGrants.IdCoachDataAccessLogs.DataScopeIdreferencesDataScopes.Id