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)

Columns of the CoachAssignments table
ColumnTypeConstraintsDescription
Iduuidprimary key, not null
CoachClientIduuidnot null, references CoachClients.IdRESTRICT.
CoachIduuidnot null, references Coaches.Id
ClientIdtextnot null, references Users.Id
TargetTypetextnot null`CoachAssignmentTargetType`.
TargetIduuidnot nullPOLYMORPHIC — no FK. Resolve via TargetType against Programs / MealPlans / FitnessPlans / UserGoals / Workouts.
Statustextnot null`CoachAssignmentStatus`.
AssignedAttimestamp with time zonenot null
RespondedAttimestamp with time zone
CompletedAttimestamp with time zone
WithdrawnAttimestamp with time zone
Notecharacter varying(2000)Coach note to the client.
CreatedAttimestamp with time zonenot null
ModifiedAttimestamp with time zone
IsDeletedbooleannot null
DeletedAttimestamp with time zone

Indexes (3)

  • (CoachClientId, Status) (IX_CoachAssignments_CoachClientId_Status)
  • (ClientId, Status) (IX_CoachAssignments_ClientId_Status)
  • (TargetType, TargetId) (IX_CoachAssignments_TargetType_TargetId)

Relationships