CoachAccessRequests table
The CoachAccessRequests table in the FitStack - V2 schema has 16 columns, keyed by Id, with 5 foreign keys to CoachClients, Coaches, Users and CoachAccessGrants. 2 columns in CoachAccessRequestScopes and CoachAccessGrants reference it.
The ask. Immutable once answered — a coach who wants more scopes files a new request rather than editing an approved one, so the record of what the client actually consented to cannot be rewritten after the fact. Enforce one pending request per relationship with a partial unique index: CREATE UNIQUE INDEX "IX_CoachAccessRequests_OnePending" ON "CoachAccessRequests" ("CoachClientId") WHERE "Status" = 'Pending' AND "IsDeleted" = false;
Columns (16)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null | |
| CoachClientId | uuid | not null, references CoachClients.Id | RESTRICT. A request only exists inside a relationship. |
| CoachId | uuid | not null, references Coaches.Id | Denormalised from CoachClients so the coach-side list query needs no join. |
| ClientId | text | not null, references Users.Id | Denormalised, same reason. |
| Status | text | not null | `AccessRequestStatus`. |
| Reason | character varying(2000) | not null | Required. The coach must say WHY, and the client sees this verbatim on the consent screen. |
| RequestedDurationDays | integer | Null = open-ended. The client may shorten it when approving. | |
| ExpiresAt | timestamp with time zone | not null | When the REQUEST goes stale — not the grant. |
| RespondedAt | timestamp with time zone | ||
| RespondedByUserId | text | references Users.Id | Normally the client. Recorded explicitly for support-assisted decisions. |
| DecisionNote | character varying(2000) | ||
| ResultingGrantId | uuid | references CoachAccessGrants.Id | Set on approval or partial approval. |
| CreatedAt | timestamp with time zone | not null | |
| ModifiedAt | timestamp with time zone | ||
| IsDeleted | boolean | not null | |
| DeletedAt | timestamp with time zone |
Indexes (3)
(ClientId, Status)(IX_CoachAccessRequests_ClientId_Status)(CoachId, Status)(IX_CoachAccessRequests_CoachId_Status)(ExpiresAt)(IX_CoachAccessRequests_ExpiresAt)
Relationships
CoachAccessRequests.CoachClientIdreferencesCoachClients.IdCoachAccessRequests.CoachIdreferencesCoaches.IdCoachAccessRequests.ClientIdreferencesUsers.IdCoachAccessRequests.RespondedByUserIdreferencesUsers.IdCoachAccessRequests.ResultingGrantIdreferencesCoachAccessGrants.IdCoachAccessRequestScopes.AccessRequestIdreferencesCoachAccessRequestsCoachAccessGrants.SourceRequestIdreferencesCoachAccessRequests