CoachAssignments table
The CoachAssignments table in the FitStack - V2 schema has 16 columns, keyed by Id, with 3 foreign keys to CoachClients, Coaches and Users.
**Replaces the v1 approach.** v1 grafted a `AssignedByCoachId uuid` + `AssignedAt` column pair onto four unrelated tables — `UserGoals`, `ProgramEnrollments`, `MealPlanEnrollments`, `FitnessPlanEnrollments` — with no FK on any of them. Costs of that shape: - "what has this coach assigned me" was a four-way UNION; - a fifth assignable type meant another migration on another table; - the client could not decline, and nothing recorded withdrawal. One table, one polymorphic target, one lifecycle. The trade is a lost FK on `TargetId`, which is already the established pattern here (see `PlanSubscription.PlanId`, `ScheduledItemLog.LogId`, `UserEvent.EntityId`). Writing an assignment requires an active relationship. It does NOT require a data-access grant — assigning work is a write into the client account, not a read of their history. The two authorizations are separate.
Columns (16)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null | |
| CoachClientId | uuid | not null, references CoachClients.Id | RESTRICT. |
| CoachId | uuid | not null, references Coaches.Id | |
| ClientId | text | not null, references Users.Id | |
| TargetType | text | not null | `CoachAssignmentTargetType`. |
| TargetId | uuid | not null | POLYMORPHIC — no FK. Resolve via TargetType against Programs / MealPlans / FitnessPlans / UserGoals / Workouts. |
| Status | text | not null | `CoachAssignmentStatus`. |
| AssignedAt | timestamp with time zone | not null | |
| RespondedAt | timestamp with time zone | ||
| CompletedAt | timestamp with time zone | ||
| WithdrawnAt | timestamp with time zone | ||
| Note | character varying(2000) | Coach note to the client. | |
| CreatedAt | timestamp with time zone | not null | |
| ModifiedAt | timestamp with time zone | ||
| IsDeleted | boolean | not null | |
| DeletedAt | timestamp with time zone |
Indexes (3)
(CoachClientId, Status)(IX_CoachAssignments_CoachClientId_Status)(ClientId, Status)(IX_CoachAssignments_ClientId_Status)(TargetType, TargetId)(IX_CoachAssignments_TargetType_TargetId)
Relationships
CoachAssignments.CoachClientIdreferencesCoachClients.IdCoachAssignments.CoachIdreferencesCoaches.IdCoachAssignments.ClientIdreferencesUsers.Id