Templates/Commerce

Multi-vendor marketplace database schema

Sellers with listings, buyer orders split per seller, payouts and reviews.

7 tables, 8 relationships

Opens as a new diagram you can change. Free.

Tables

users

  • iduuid not null
  • emailtext not null
  • nametext not null
  • created_attimestamptz not null

sellers

  • iduuid not null
  • user_id> usersuuid not null
  • shop_nametext not null
  • payout_accounttext
  • created_attimestamptz not null

listings

  • iduuid not null
  • seller_id> sellersuuid not null
  • titletext not null
  • pricenumeric(10,2) not null
  • quantityinteger not null
  • activeboolean not null
  • created_attimestamptz not null

orders

  • iduuid not null
  • buyer_id> usersuuid not null
  • totalnumeric(10,2) not null
  • statustext not null
  • created_attimestamptz not null

order_items

  • iduuid not null
  • order_id> ordersuuid not null
  • listing_id> listingsuuid not null
  • seller_id> sellersuuid not null
  • quantityinteger not null
  • pricenumeric(10,2) not null
  • created_attimestamptz not null

payouts

  • iduuid not null
  • seller_id> sellersuuid not null
  • amountnumeric(10,2) not null
  • paid_attimestamptz
  • created_attimestamptz not null

reviews

  • iduuid not null
  • order_item_id> order_itemsuuid not null
  • ratinginteger not null
  • bodytext
  • 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 "listings" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "seller_id" UUID NOT NULL,
  "title" TEXT NOT NULL,
  "price" NUMERIC(10,2) NOT NULL,
  "quantity" INTEGER DEFAULT 1 NOT NULL,
  "active" BOOLEAN DEFAULT true 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,
  "listing_id" UUID NOT NULL,
  "seller_id" UUID NOT NULL,
  "quantity" INTEGER NOT NULL,
  "price" NUMERIC(10,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "orders" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "buyer_id" UUID NOT NULL,
  "total" NUMERIC(10,2) NOT NULL,
  "status" TEXT DEFAULT 'pending' NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "payouts" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "seller_id" UUID NOT NULL,
  "amount" NUMERIC(10,2) NOT NULL,
  "paid_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "reviews" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "order_item_id" UUID NOT NULL UNIQUE,
  "rating" INTEGER NOT NULL,
  "body" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "sellers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "user_id" UUID NOT NULL UNIQUE,
  "shop_name" TEXT NOT NULL UNIQUE,
  "payout_account" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

ALTER TABLE "sellers" ADD CONSTRAINT "fk_sellers_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "listings" ADD CONSTRAINT "fk_listings_seller_id" FOREIGN KEY ("seller_id") REFERENCES "sellers" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "orders" ADD CONSTRAINT "fk_orders_buyer_id" FOREIGN KEY ("buyer_id") REFERENCES "users" ("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_listing_id" FOREIGN KEY ("listing_id") REFERENCES "listings" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "order_items" ADD CONSTRAINT "fk_order_items_seller_id" FOREIGN KEY ("seller_id") REFERENCES "sellers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "payouts" ADD CONSTRAINT "fk_payouts_seller_id" FOREIGN KEY ("seller_id") REFERENCES "sellers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "reviews" ADD CONSTRAINT "fk_reviews_order_item_id" FOREIGN KEY ("order_item_id") REFERENCES "order_items" ("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.