CoachAccessGrantScopes table
The CoachAccessGrantScopes table in the FitStack - V2 schema has 7 columns, keyed by Id, with 2 foreign keys to CoachAccessGrants and DataScopes.
**What the coach may actually see.** The enforcement query is: SELECT gs.* FROM "CoachAccessGrantScopes" gs JOIN "CoachAccessGrants" g ON g."Id" = gs."AccessGrantId" JOIN "DataScopes" s ON s."Id" = gs."DataScopeId" WHERE g."CoachId" = @coachId AND g."ClientId" = @clientId AND g."Status" = 'Active' AND (g."ExpiresAt" IS NULL OR g."ExpiresAt" > now()) AND gs."RevokedAt" IS NULL AND s."Key" = @requiredScopeKey; No row => 403, and a `CoachDataAccessLogs` entry with the matching `DeniedX` outcome. A non-null `HistoryWindowDays` additionally clamps the date filter on the underlying query — silently, not as an error.
Columns (7)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null | |
| AccessGrantId | uuid | not null, references CoachAccessGrants.Id | CASCADE. |
| DataScopeId | uuid | not null, references DataScopes.Id | RESTRICT. |
| HistoryWindowDays | integer | Coach may read records no older than now() - this. Null = all history. Must respect DataScopes.MaxHistoryWindowDays. | |
| AllowsRealtimePush | boolean | not null | Governs the SignalR firehose that v1 ran unconditionally. Defaults to FALSE: live streaming of a client activity is opt-in, per scope. |
| GrantedAt | timestamp with time zone | not null | Per-scope, because scopes can be added to a grant later. |
| RevokedAt | timestamp with time zone | Per-scope revocation without killing the whole grant — the client can withdraw nutrition while keeping training. |
Indexes (2)
(AccessGrantId, DataScopeId)unique (IX_CoachAccessGrantScopes_GrantId_ScopeId)(DataScopeId)(IX_CoachAccessGrantScopes_DataScopeId)
Relationships
CoachAccessGrantScopes.AccessGrantIdreferencesCoachAccessGrants.IdCoachAccessGrantScopes.DataScopeIdreferencesDataScopes.Id