CoachClients table

The CoachClients table in the FitStack - V2 schema has 13 columns, keyed by Id, with 3 foreign keys to Coaches and Users. 9 columns in CoachInvitations, CoachClientStatusEvents, CoachAccessRequests, CoachAccessGrants and 5 more reference it.

The working relationship. Exists only after an invitation is accepted. **The unique index changed shape.** v1 had a plain unique on `(CoachId, ClientId)`, which permanently barred re-engagement. v2 needs a PARTIAL unique index that DBML cannot express: CREATE UNIQUE INDEX "IX_CoachClients_CoachId_ClientId_Live" ON "CoachClients" ("CoachId", "ClientId") WHERE "Status" <> 'Ended' AND "IsDeleted" = false; So: one live relationship per pair, unlimited historical ones. **On transition to `Ended`, every live `CoachAccessGrant` for this pair must be revoked in the same transaction.** Nothing in the schema forces it; it belongs in the command handler and in an integration test.

Columns (13)

Columns of the CoachClients table
ColumnTypeConstraintsDescription
Iduuidprimary key, not null
CoachIduuidnot null, references Coaches.IdRESTRICT — an approved coach with clients cannot be deleted out from under them.
ClientIdtextnot null, references Users.Idv2 FIX: real FK. Was dangling text.
Statustextnot null`CoachClientStatus`.
StartedAttimestamp with time zonenot nullv2: not null. A relationship exists only once accepted, so it always has a start.
EndedAttimestamp with time zone
EndReasoncharacter varying(2000)
EndedByUserIdtextreferences Users.Idv2 ADD: who ended it. v1 recorded the reason but not the actor.
StripeSubscriptionIdtextDenormalised pointer; the ledger is in 64.
CreatedAttimestamp with time zonenot null
ModifiedAttimestamp with time zone
IsDeletedbooleannot null
DeletedAttimestamp with time zone

Indexes (2)

  • (ClientId) (IX_CoachClients_ClientId)
  • (CoachId, Status) (IX_CoachClients_CoachId_Status)

Relationships