Templates/Commerce

Restaurant ordering database schema

Menus with items and modifiers, and orders for dine-in or takeaway.

7 tables, 8 relationships

Opens as a new diagram you can change. Free.

Tables

restaurants

  • iduuid not null
  • nametext not null
  • addresstext not null
  • created_attimestamptz not null

menus

  • iduuid not null
  • restaurant_id> restaurantsuuid not null
  • nametext not null
  • activeboolean not null
  • created_attimestamptz not null

menu_items

  • iduuid not null
  • menu_id> menusuuid not null
  • nametext not null
  • descriptiontext
  • pricenumeric(8,2) not null
  • availableboolean not null
  • created_attimestamptz not null

modifiers

  • iduuid not null
  • menu_item_id> menu_itemsuuid not null
  • nametext not null
  • price_deltanumeric(8,2) not null
  • created_attimestamptz not null

orders

  • iduuid not null
  • restaurant_id> restaurantsuuid not null
  • kindtext not null
  • table_numbertext
  • statustext not null
  • totalnumeric(10,2) not null
  • created_attimestamptz not null

order_items

  • iduuid not null
  • order_id> ordersuuid not null
  • menu_item_id> menu_itemsuuid not null
  • quantityinteger not null
  • notestext
  • created_attimestamptz not null

order_item_modifiers

  • iduuid not null
  • order_item_id> order_itemsuuid not null
  • modifier_id> modifiersuuid 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 "menu_items" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "menu_id" UUID NOT NULL,
  "name" TEXT NOT NULL,
  "description" TEXT,
  "price" NUMERIC(8,2) NOT NULL,
  "available" BOOLEAN DEFAULT true NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "menus" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "restaurant_id" UUID NOT NULL,
  "name" TEXT NOT NULL,
  "active" BOOLEAN DEFAULT true NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "modifiers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "menu_item_id" UUID NOT NULL,
  "name" TEXT NOT NULL,
  "price_delta" NUMERIC(8,2) DEFAULT 0 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "order_item_modifiers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "order_item_id" UUID NOT NULL,
  "modifier_id" UUID NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "order_items" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "order_id" UUID NOT NULL,
  "menu_item_id" UUID NOT NULL,
  "quantity" INTEGER NOT NULL,
  "notes" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "orders" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "restaurant_id" UUID NOT NULL,
  "kind" TEXT DEFAULT 'dine_in' NOT NULL,
  "table_number" TEXT,
  "status" TEXT DEFAULT 'open' NOT NULL,
  "total" NUMERIC(10,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

ALTER TABLE "menus" ADD CONSTRAINT "fk_menus_restaurant_id" FOREIGN KEY ("restaurant_id") REFERENCES "restaurants" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "menu_items" ADD CONSTRAINT "fk_menu_items_menu_id" FOREIGN KEY ("menu_id") REFERENCES "menus" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "modifiers" ADD CONSTRAINT "fk_modifiers_menu_item_id" FOREIGN KEY ("menu_item_id") REFERENCES "menu_items" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "orders" ADD CONSTRAINT "fk_orders_restaurant_id" FOREIGN KEY ("restaurant_id") REFERENCES "restaurants" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "order_items" ADD CONSTRAINT "fk_order_items_order_id" FOREIGN KEY ("order_id") REFERENCES "orders" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "order_items" ADD CONSTRAINT "fk_order_items_menu_item_id" FOREIGN KEY ("menu_item_id") REFERENCES "menu_items" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "order_item_modifiers" ADD CONSTRAINT "fk_order_item_modifiers_order_item_id" FOREIGN KEY ("order_item_id") REFERENCES "order_items" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "order_item_modifiers" ADD CONSTRAINT "fk_order_item_modifiers_modifier_id" FOREIGN KEY ("modifier_id") REFERENCES "modifiers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

More Commerce templates

Start with one diagram, free

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