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)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null | |
| CoachId | uuid | not null, references Coaches.Id | RESTRICT — an approved coach with clients cannot be deleted out from under them. |
| ClientId | text | not null, references Users.Id | v2 FIX: real FK. Was dangling text. |
| Status | text | not null | `CoachClientStatus`. |
| StartedAt | timestamp with time zone | not null | v2: not null. A relationship exists only once accepted, so it always has a start. |
| EndedAt | timestamp with time zone | ||
| EndReason | character varying(2000) | ||
| EndedByUserId | text | references Users.Id | v2 ADD: who ended it. v1 recorded the reason but not the actor. |
| StripeSubscriptionId | text | Denormalised pointer; the ledger is in 64. | |
| CreatedAt | timestamp with time zone | not null | |
| ModifiedAt | timestamp with time zone | ||
| IsDeleted | boolean | not null | |
| DeletedAt | timestamp with time zone |
Indexes (2)
(ClientId)(IX_CoachClients_ClientId)(CoachId, Status)(IX_CoachClients_CoachId_Status)
Relationships
CoachClients.CoachIdreferencesCoaches.IdCoachClients.ClientIdreferencesUsers.IdCoachClients.EndedByUserIdreferencesUsers.IdCoachInvitations.ResultingCoachClientIdreferencesCoachClientsCoachClientStatusEvents.CoachClientIdreferencesCoachClientsCoachAccessRequests.CoachClientIdreferencesCoachClientsCoachAccessGrants.CoachClientIdreferencesCoachClientsCoachAssignments.CoachClientIdreferencesCoachClientsCoachCheckIns.CoachClientIdreferencesCoachClientsCoachAppointments.CoachClientIdreferencesCoachClientsCoachClientSubscriptions.CoachClientIdreferencesCoachClientsCoachClientInvoices.CoachClientIdreferencesCoachClients