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)

Columns of the CoachInvitations table
ColumnTypeConstraintsDescription
Iduuidprimary key, not null
CoachIduuidnot null, references Coaches.IdCASCADE.
ClientIdtextnot null, references Users.Idv2 FIX: real FK.
Directiontextnot null`CoachInvitationDirection`.
Statustextnot null`CoachInvitationStatus`.
Messagecharacter varying(2000)Free text from the initiator.
SentByUserIdtextnot null, references Users.Id
ExpiresAttimestamp with time zonenot nullv2 ADD: invitations rot. A pending request from eight months ago should not be acceptable.
RespondedAttimestamp with time zone
RespondedByUserIdtextreferences Users.Id
DeclineReasoncharacter varying(2000)
ResultingCoachClientIduuidreferences CoachClients.IdSet on acceptance. Null otherwise.
CreatedAttimestamp with time zonenot null
ModifiedAttimestamp with time zone
IsDeletedbooleannot null
DeletedAttimestamp with time zone

Indexes (3)

  • (CoachId, Status) (IX_CoachInvitations_CoachId_Status)
  • (ClientId, Status) (IX_CoachInvitations_ClientId_Status)
  • (ExpiresAt) (IX_CoachInvitations_ExpiresAt)

Relationships

  • CoachInvitations.CoachId references Coaches.Id
  • CoachInvitations.ClientId references Users.Id
  • CoachInvitations.SentByUserId references Users.Id
  • CoachInvitations.RespondedByUserId references Users.Id
  • CoachInvitations.ResultingCoachClientId references CoachClients.Id