CoachAppointments table
The CoachAppointments table in the FitStack - V2 schema has 15 columns, keyed by Id, with 5 foreign keys to VideoCallSessions, Coaches, Users and CoachClients.
v1 also carried `VideoCallSessionId uuid` here while `VideoCallSessions` carried `AppointmentId` — a denormalised cycle with no FK on either side that could disagree with itself. v2 keeps only the one real direction: `VideoCallSessions.AppointmentId`. v2 ADD — double-booking prevention, which v1 had nothing for: ALTER TABLE "CoachAppointments" ADD CONSTRAINT "EX_CoachAppointments_NoOverlap" EXCLUDE USING gist ( "CoachId" WITH =, tstzrange("StartsAt", "EndsAt") WITH && ) WHERE ("Status" = 'Scheduled' AND "IsDeleted" = false); Requires the btree_gist extension.
Columns (15)
| Column | Type | Constraints | Description |
|---|---|---|---|
| Id | uuid | primary key, not null, references VideoCallSessions.AppointmentId | |
| CoachId | uuid | not null, references Coaches.Id | RESTRICT. |
| ClientId | text | not null, references Users.Id | v2 FIX: real FK. |
| CoachClientId | uuid | references CoachClients.Id | v2 ADD. Null for a consultation booked before any relationship exists. |
| StartsAt | timestamp with time zone | not null | |
| DurationMinutes | integer | not null | |
| EndsAt | timestamp with time zone | not null | v2 ADD: stored, not derived. Needed by the overlap exclusion constraint below — Postgres cannot build a range over a computed interval in an EXCLUDE clause. |
| Status | text | not null | `AppointmentStatus`. |
| CancellationReason | character varying(2000) | ||
| CancelledAt | timestamp with time zone | ||
| CancelledByUserId | text | references Users.Id | v2 FIX: real FK. |
| CreatedAt | timestamp with time zone | not null | |
| ModifiedAt | timestamp with time zone | ||
| IsDeleted | boolean | not null | |
| DeletedAt | timestamp with time zone |
Indexes (3)
(CoachId, StartsAt)(IX_CoachAppointments_CoachId_StartsAt)(ClientId, StartsAt)(IX_CoachAppointments_ClientId_StartsAt)(Status, StartsAt)(IX_CoachAppointments_Status_StartsAt)
Relationships
CoachAppointments.IdreferencesVideoCallSessions.AppointmentIdCoachAppointments.CoachIdreferencesCoaches.IdCoachAppointments.ClientIdreferencesUsers.IdCoachAppointments.CoachClientIdreferencesCoachClients.IdCoachAppointments.CancelledByUserIdreferencesUsers.Id