Food delivery database schema
Customers order from restaurants; couriers pick up, deliver and get rated.
6 tables, 5 relationships
Opens as a new diagram you can change. Free.
Tables
customers
- iduuid not null
- nametext not null
- phonetext not null
- created_attimestamptz not null
restaurants
- iduuid not null
- nametext not null
- latitudenumeric(9,6) not null
- longitudenumeric(9,6) not null
- created_attimestamptz not null
couriers
- iduuid not null
- nametext not null
- vehicletext not null
- availableboolean not null
- created_attimestamptz not null
orders
- iduuid not null
- customer_id> customersuuid not null
- restaurant_id> restaurantsuuid not null
- delivery_addresstext not null
- totalnumeric(10,2) not null
- statustext not null
- created_attimestamptz not null
deliveries
- iduuid not null
- order_id> ordersuuid not null
- courier_id> couriersuuid
- picked_up_attimestamptz
- delivered_attimestamptz
- created_attimestamptz not null
ratings
- iduuid not null
- order_id> ordersuuid not null
- food_ratinginteger not null
- courier_ratinginteger
- commenttext
- 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 "couriers" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"vehicle" TEXT NOT NULL,
"available" BOOLEAN DEFAULT false NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "customers" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"phone" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "deliveries" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"order_id" UUID NOT NULL UNIQUE,
"courier_id" UUID,
"picked_up_at" TIMESTAMPTZ,
"delivered_at" TIMESTAMPTZ,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "orders" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"customer_id" UUID NOT NULL,
"restaurant_id" UUID NOT NULL,
"delivery_address" TEXT NOT NULL,
"total" NUMERIC(10,2) NOT NULL,
"status" TEXT DEFAULT 'placed' NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "ratings" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"order_id" UUID NOT NULL UNIQUE,
"food_rating" INTEGER NOT NULL,
"courier_rating" INTEGER,
"comment" TEXT,
"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,
"latitude" NUMERIC(9,6) NOT NULL,
"longitude" NUMERIC(9,6) NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "orders" ADD CONSTRAINT "fk_orders_customer_id" FOREIGN KEY ("customer_id") REFERENCES "customers" ("id") ON DELETE NO ACTION 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 "deliveries" ADD CONSTRAINT "fk_deliveries_order_id" FOREIGN KEY ("order_id") REFERENCES "orders" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "deliveries" ADD CONSTRAINT "fk_deliveries_courier_id" FOREIGN KEY ("courier_id") REFERENCES "couriers" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;
ALTER TABLE "ratings" ADD CONSTRAINT "fk_ratings_order_id" FOREIGN KEY ("order_id") REFERENCES "orders" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;More Commerce templates
- E-commerce storeCustomers, products and categories, orders with line items, and addresses.
- Multi-vendor marketplaceSellers with listings, buyer orders split per seller, payouts and reviews.
- Inventory & warehousesStock levels per warehouse, stock movements, suppliers and purchase orders.
- Point of saleStores, registers and staff ringing up sales with mixed payments.
- Restaurant orderingMenus with items and modifiers, and orders for dine-in or takeaway.
- Promotions & couponsCampaigns issuing coupon codes, with redemption tracking against orders.
- Product catalogue with variantsProducts with options (size, colour), variants, images and nested categories.
- Subscription boxMonthly boxes, what goes in each, subscribers and their shipments.
- AuctionsAuctions with lots, timed bids, watchers and winners.
- Product catalogue (MongoDB)Products with embedded variants and images, categories and reviews that reference them.
- Orders, single table (DynamoDB)Customers, orders and order lines in one table keyed by PK and SK, with a GSI for orders by status.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.