CoachAccessGrants table
The CoachAccessGrants table in the FitStack - V2 schema has 17 columns, keyed by Id, with 7 foreign keys to CoachClients, Coaches, Users, CoachAccessRequests and 1 more. 3 columns in CoachAccessRequests, CoachAccessGrantScopes and CoachDataAccessLogs reference it.
**The authorization record.** Every coach read of client data resolves through exactly one row here plus its scope rows. Never hard-delete and never soft-delete a grant to revoke it — set `Status = Revoked` with `RevokedAt`. A deleted grant destroys the evidence of what was once permitted, which is the one question that matters after a complaint. At most one Active grant per relationship: CREATE UNIQUE INDEX "IX_CoachAccessGrants_OneActive" ON "CoachAccessGrants" ("CoachClientId") WHERE "Status" = 'Active' AND "IsDeleted" = false; Widening consent = create a new grant, point the old one at it via `SupersededByGrantId`, set the old to `Superseded`. The history stays readable end to end. Cascading obligations (application-enforced, all worth an integration test): - `CoachClients.Status -> Ended` => revoke every Active grant for the pair - `CoachClients.Status -> Paused` => suspend them - `Coaches.Status -> Suspended` => suspend every grant held by the coach - client deletes their account => revoke all grants naming them
Columns (17)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null | |
| CoachClientId | uuid | not null, references CoachClients.Id | RESTRICT. |
| CoachId | uuid | not null, references Coaches.Id | Denormalised for the enforcement lookup, which runs on every read. |
| ClientId | text | not null, references Users.Id | Denormalised, same reason. |
| SourceRequestId | uuid | references CoachAccessRequests.Id | Null only for grants created by an admin or a data migration. |
| Status | text | not null | `AccessGrantStatus`. |
| GrantedAt | timestamp with time zone | not null | |
| GrantedByUserId | text | not null, references Users.Id | The consenting client. Not nullable: consent always has an author. |
| ExpiresAt | timestamp with time zone | Null = until revoked. The UI should push hard toward a bounded window. | |
| RevokedAt | timestamp with time zone | ||
| RevokedByUserId | text | references Users.Id | |
| RevokeReason | character varying(2000) | ||
| SupersededByGrantId | uuid | references CoachAccessGrants.Id | Self-reference. Set when a newer grant replaces this one. |
| CreatedAt | timestamp with time zone | not null | |
| ModifiedAt | timestamp with time zone | ||
| IsDeleted | boolean | not null | |
| DeletedAt | timestamp with time zone |
Indexes (3)
(CoachId, ClientId, Status)(IX_CoachAccessGrants_CoachId_ClientId_Status)(ClientId, Status)(IX_CoachAccessGrants_ClientId_Status)(ExpiresAt)(IX_CoachAccessGrants_ExpiresAt)
Relationships
CoachAccessGrants.CoachClientIdreferencesCoachClients.IdCoachAccessGrants.CoachIdreferencesCoaches.IdCoachAccessGrants.ClientIdreferencesUsers.IdCoachAccessGrants.SourceRequestIdreferencesCoachAccessRequests.IdCoachAccessGrants.GrantedByUserIdreferencesUsers.IdCoachAccessGrants.RevokedByUserIdreferencesUsers.IdCoachAccessGrants.SupersededByGrantIdreferencesCoachAccessGrants.IdCoachAccessRequests.ResultingGrantIdreferencesCoachAccessGrantsCoachAccessGrantScopes.AccessGrantIdreferencesCoachAccessGrantsCoachDataAccessLogs.AccessGrantIdreferencesCoachAccessGrants