Inventory & warehouses database schema
Stock levels per warehouse, stock movements, suppliers and purchase orders.
7 tables, 8 relationships
Opens as a new diagram you can change. Free.
Tables
warehouses
- iduuid not null
- nametext not null
- codetext not null
- addresstext
- created_attimestamptz not null
suppliers
- iduuid not null
- nametext not null
- emailtext
- created_attimestamptz not null
products
- iduuid not null
- skutext not null
- nametext not null
- reorder_levelinteger not null
- created_attimestamptz not null
stock_levels
- iduuid not null
- warehouse_id> warehousesuuid not null
- product_id> productsuuid not null
- on_handinteger not null
- reservedinteger not null
- created_attimestamptz not null
stock_movements
- iduuid not null
- warehouse_id> warehousesuuid not null
- product_id> productsuuid not null
- quantityinteger not null
- reasontext not null
- referencetext
- created_attimestamptz not null
purchase_orders
- iduuid not null
- supplier_id> suppliersuuid not null
- warehouse_id> warehousesuuid not null
- statustext not null
- expected_atdate
- created_attimestamptz not null
purchase_order_lines
- iduuid not null
- purchase_order_id> purchase_ordersuuid not null
- product_id> productsuuid not null
- quantityinteger not null
- unit_costnumeric(10,2) 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 "products" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"sku" TEXT NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"reorder_level" INTEGER DEFAULT 0 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "purchase_order_lines" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"purchase_order_id" UUID NOT NULL,
"product_id" UUID NOT NULL,
"quantity" INTEGER NOT NULL,
"unit_cost" NUMERIC(10,2) NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "purchase_orders" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"supplier_id" UUID NOT NULL,
"warehouse_id" UUID NOT NULL,
"status" TEXT DEFAULT 'draft' NOT NULL,
"expected_at" DATE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "stock_levels" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"warehouse_id" UUID NOT NULL,
"product_id" UUID NOT NULL,
"on_hand" INTEGER DEFAULT 0 NOT NULL,
"reserved" INTEGER DEFAULT 0 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "stock_movements" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"warehouse_id" UUID NOT NULL,
"product_id" UUID NOT NULL,
"quantity" INTEGER NOT NULL,
"reason" TEXT NOT NULL,
"reference" TEXT,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "suppliers" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"email" TEXT,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "warehouses" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"code" TEXT NOT NULL UNIQUE,
"address" TEXT,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "stock_levels" ADD CONSTRAINT "fk_stock_levels_warehouse_id" FOREIGN KEY ("warehouse_id") REFERENCES "warehouses" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "stock_levels" ADD CONSTRAINT "fk_stock_levels_product_id" FOREIGN KEY ("product_id") REFERENCES "products" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "stock_movements" ADD CONSTRAINT "fk_stock_movements_warehouse_id" FOREIGN KEY ("warehouse_id") REFERENCES "warehouses" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "stock_movements" ADD CONSTRAINT "fk_stock_movements_product_id" FOREIGN KEY ("product_id") REFERENCES "products" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "purchase_orders" ADD CONSTRAINT "fk_purchase_orders_supplier_id" FOREIGN KEY ("supplier_id") REFERENCES "suppliers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "purchase_orders" ADD CONSTRAINT "fk_purchase_orders_warehouse_id" FOREIGN KEY ("warehouse_id") REFERENCES "warehouses" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "purchase_order_lines" ADD CONSTRAINT "fk_purchase_order_lines_purchase_order_id" FOREIGN KEY ("purchase_order_id") REFERENCES "purchase_orders" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "purchase_order_lines" ADD CONSTRAINT "fk_purchase_order_lines_product_id" FOREIGN KEY ("product_id") REFERENCES "products" ("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.
- 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.
- Food deliveryCustomers order from restaurants; couriers pick up, deliver and get rated.
- 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.