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)

Columns of the CoachAccessGrants table
ColumnTypeConstraintsDescription
Iduuidprimary key, not null
CoachClientIduuidnot null, references CoachClients.IdRESTRICT.
CoachIduuidnot null, references Coaches.IdDenormalised for the enforcement lookup, which runs on every read.
ClientIdtextnot null, references Users.IdDenormalised, same reason.
SourceRequestIduuidreferences CoachAccessRequests.IdNull only for grants created by an admin or a data migration.
Statustextnot null`AccessGrantStatus`.
GrantedAttimestamp with time zonenot null
GrantedByUserIdtextnot null, references Users.IdThe consenting client. Not nullable: consent always has an author.
ExpiresAttimestamp with time zoneNull = until revoked. The UI should push hard toward a bounded window.
RevokedAttimestamp with time zone
RevokedByUserIdtextreferences Users.Id
RevokeReasoncharacter varying(2000)
SupersededByGrantIduuidreferences CoachAccessGrants.IdSelf-reference. Set when a newer grant replaces this one.
CreatedAttimestamp with time zonenot null
ModifiedAttimestamp with time zone
IsDeletedbooleannot null
DeletedAttimestamp with time zone

Indexes (3)

  • (CoachId, ClientId, Status) (IX_CoachAccessGrants_CoachId_ClientId_Status)
  • (ClientId, Status) (IX_CoachAccessGrants_ClientId_Status)
  • (ExpiresAt) (IX_CoachAccessGrants_ExpiresAt)

Relationships