Templates/Health

Gym membership database schema

Members on plans, scheduled classes with bookings, and door check-ins.

8 tables, 7 relationships

Opens as a new diagram you can change. Free.

Tables

members

  • iduuid not null
  • full_nametext not null
  • emailtext not null
  • created_attimestamptz not null

membership_plans

  • iduuid not null
  • nametext not null
  • monthly_pricenumeric(8,2) not null
  • created_attimestamptz not null

memberships

  • iduuid not null
  • member_id> membersuuid not null
  • plan_id> membership_plansuuid not null
  • starts_ondate not null
  • ends_ondate
  • created_attimestamptz not null

instructors

  • iduuid not null
  • full_nametext not null
  • created_attimestamptz not null

classes

  • iduuid not null
  • nametext not null
  • capacityinteger not null
  • created_attimestamptz not null

class_sessions

  • iduuid not null
  • class_id> classesuuid not null
  • instructor_id> instructorsuuid not null
  • starts_attimestamptz not null
  • created_attimestamptz not null

class_bookings

  • iduuid not null
  • session_id> class_sessionsuuid not null
  • member_id> membersuuid not null
  • attendedboolean not null
  • created_attimestamptz not null

check_ins

  • iduuid not null
  • member_id> membersuuid not null
  • checked_in_attimestamptz not null
  • created_attimestamptz not null

As PostgreSQL

The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.

CREATE TABLE "check_ins" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "member_id" UUID NOT NULL,
  "checked_in_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "class_bookings" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "session_id" UUID NOT NULL,
  "member_id" UUID NOT NULL,
  "attended" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "class_sessions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "class_id" UUID NOT NULL,
  "instructor_id" UUID NOT NULL,
  "starts_at" TIMESTAMPTZ NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "classes" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "capacity" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "instructors" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "members" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "membership_plans" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "monthly_price" NUMERIC(8,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "memberships" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "member_id" UUID NOT NULL,
  "plan_id" UUID NOT NULL,
  "starts_on" DATE NOT NULL,
  "ends_on" DATE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "memberships" ADD CONSTRAINT "fk_memberships_member_id" FOREIGN KEY ("member_id") REFERENCES "members" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "memberships" ADD CONSTRAINT "fk_memberships_plan_id" FOREIGN KEY ("plan_id") REFERENCES "membership_plans" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "class_sessions" ADD CONSTRAINT "fk_class_sessions_class_id" FOREIGN KEY ("class_id") REFERENCES "classes" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "class_sessions" ADD CONSTRAINT "fk_class_sessions_instructor_id" FOREIGN KEY ("instructor_id") REFERENCES "instructors" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "class_bookings" ADD CONSTRAINT "fk_class_bookings_session_id" FOREIGN KEY ("session_id") REFERENCES "class_sessions" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "class_bookings" ADD CONSTRAINT "fk_class_bookings_member_id" FOREIGN KEY ("member_id") REFERENCES "members" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "check_ins" ADD CONSTRAINT "fk_check_ins_member_id" FOREIGN KEY ("member_id") REFERENCES "members" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

More Health templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.