CoachInvitations table
The CoachInvitations table in the FitStack - V2 schema has 16 columns, keyed by Id, with 5 foreign keys to Coaches, Users and CoachClients.
An offer, in either direction. Many invitations may exist over time for the same pair — that is the point — so there is NO unique index on `(CoachId, ClientId)`. Application rules the schema cannot state: - at most one `Pending` invitation per `(CoachId, ClientId)` at a time (enforce with a partial unique index: `... UNIQUE ("CoachId","ClientId") WHERE "Status" = 'Pending'`); - reject if a `UserBlock` exists in either direction; - reject if the coach is not `Approved`; - reject if the coach is at `MaxActiveClients`. Accepting an invitation does NOT grant data access. It creates the relationship; reading the client metrics needs a separate, explicit consent step (62). Keeping these apart is the whole design.
Columns (16)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null | |
| CoachId | uuid | not null, references Coaches.Id | CASCADE. |
| ClientId | text | not null, references Users.Id | v2 FIX: real FK. |
| Direction | text | not null | `CoachInvitationDirection`. |
| Status | text | not null | `CoachInvitationStatus`. |
| Message | character varying(2000) | Free text from the initiator. | |
| SentByUserId | text | not null, references Users.Id | |
| ExpiresAt | timestamp with time zone | not null | v2 ADD: invitations rot. A pending request from eight months ago should not be acceptable. |
| RespondedAt | timestamp with time zone | ||
| RespondedByUserId | text | references Users.Id | |
| DeclineReason | character varying(2000) | ||
| ResultingCoachClientId | uuid | references CoachClients.Id | Set on acceptance. Null otherwise. |
| CreatedAt | timestamp with time zone | not null | |
| ModifiedAt | timestamp with time zone | ||
| IsDeleted | boolean | not null | |
| DeletedAt | timestamp with time zone |
Indexes (3)
(CoachId, Status)(IX_CoachInvitations_CoachId_Status)(ClientId, Status)(IX_CoachInvitations_ClientId_Status)(ExpiresAt)(IX_CoachInvitations_ExpiresAt)
Relationships
CoachInvitations.CoachIdreferencesCoaches.IdCoachInvitations.ClientIdreferencesUsers.IdCoachInvitations.SentByUserIdreferencesUsers.IdCoachInvitations.RespondedByUserIdreferencesUsers.IdCoachInvitations.ResultingCoachClientIdreferencesCoachClients.Id