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)

Columns of the CoachAppointments table
ColumnTypeConstraintsDescription
Iduuidprimary key, not null, references VideoCallSessions.AppointmentId
CoachIduuidnot null, references Coaches.IdRESTRICT.
ClientIdtextnot null, references Users.Idv2 FIX: real FK.
CoachClientIduuidreferences CoachClients.Idv2 ADD. Null for a consultation booked before any relationship exists.
StartsAttimestamp with time zonenot null
DurationMinutesintegernot null
EndsAttimestamp with time zonenot nullv2 ADD: stored, not derived. Needed by the overlap exclusion constraint below — Postgres cannot build a range over a computed interval in an EXCLUDE clause.
Statustextnot null`AppointmentStatus`.
CancellationReasoncharacter varying(2000)
CancelledAttimestamp with time zone
CancelledByUserIdtextreferences Users.Idv2 FIX: real FK.
CreatedAttimestamp with time zonenot null
ModifiedAttimestamp with time zone
IsDeletedbooleannot null
DeletedAttimestamp with time zone

Indexes (3)

  • (CoachId, StartsAt) (IX_CoachAppointments_CoachId_StartsAt)
  • (ClientId, StartsAt) (IX_CoachAppointments_ClientId_StartsAt)
  • (Status, StartsAt) (IX_CoachAppointments_Status_StartsAt)

Relationships