Subscription box database schema
Monthly boxes, what goes in each, subscribers and their shipments.
7 tables, 7 relationships
Opens as a new diagram you can change. Free.
Tables
customers
- iduuid not null
- emailtext not null
- nametext not null
- addresstext not null
- created_attimestamptz not null
box_plans
- iduuid not null
- nametext not null
- pricenumeric(8,2) not null
- frequencytext not null
- created_attimestamptz not null
boxes
- iduuid not null
- plan_id> box_plansuuid not null
- monthdate not null
- created_attimestamptz not null
products
- iduuid not null
- nametext not null
- costnumeric(8,2) not null
- created_attimestamptz not null
box_items
- iduuid not null
- box_id> boxesuuid not null
- product_id> productsuuid not null
- quantityinteger not null
- created_attimestamptz not null
subscriptions
- iduuid not null
- customer_id> customersuuid not null
- plan_id> box_plansuuid not null
- activeboolean not null
- paused_untildate
- created_attimestamptz not null
shipments
- iduuid not null
- subscription_id> subscriptionsuuid not null
- box_id> boxesuuid not null
- tracking_numbertext
- shipped_attimestamptz
- 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 "box_items" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"box_id" UUID NOT NULL,
"product_id" UUID NOT NULL,
"quantity" INTEGER DEFAULT 1 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "box_plans" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"price" NUMERIC(8,2) NOT NULL,
"frequency" TEXT DEFAULT 'monthly' NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "boxes" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"plan_id" UUID NOT NULL,
"month" DATE NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "customers" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"email" TEXT NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"address" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "products" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"cost" NUMERIC(8,2) NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "shipments" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"subscription_id" UUID NOT NULL,
"box_id" UUID NOT NULL,
"tracking_number" TEXT,
"shipped_at" TIMESTAMPTZ,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "subscriptions" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"customer_id" UUID NOT NULL,
"plan_id" UUID NOT NULL,
"active" BOOLEAN DEFAULT true NOT NULL,
"paused_until" DATE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "boxes" ADD CONSTRAINT "fk_boxes_plan_id" FOREIGN KEY ("plan_id") REFERENCES "box_plans" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "box_items" ADD CONSTRAINT "fk_box_items_box_id" FOREIGN KEY ("box_id") REFERENCES "boxes" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "box_items" ADD CONSTRAINT "fk_box_items_product_id" FOREIGN KEY ("product_id") REFERENCES "products" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "subscriptions" ADD CONSTRAINT "fk_subscriptions_customer_id" FOREIGN KEY ("customer_id") REFERENCES "customers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "subscriptions" ADD CONSTRAINT "fk_subscriptions_plan_id" FOREIGN KEY ("plan_id") REFERENCES "box_plans" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "shipments" ADD CONSTRAINT "fk_shipments_subscription_id" FOREIGN KEY ("subscription_id") REFERENCES "subscriptions" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "shipments" ADD CONSTRAINT "fk_shipments_box_id" FOREIGN KEY ("box_id") REFERENCES "boxes" ("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.
- 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.
- 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.