Templates/Commerce

Point of sale database schema

Stores, registers and staff ringing up sales with mixed payments.

7 tables, 7 relationships

Opens as a new diagram you can change. Free.

Tables

stores

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

registers

  • iduuid not null
  • store_id> storesuuid not null
  • labeltext not null
  • created_attimestamptz not null

staff

  • iduuid not null
  • store_id> storesuuid not null
  • nametext not null
  • pin_hashtext not null
  • created_attimestamptz not null

products

  • iduuid not null
  • nametext not null
  • barcodetext
  • pricenumeric(10,2) not null
  • created_attimestamptz not null

sales

  • iduuid not null
  • register_id> registersuuid not null
  • staff_id> staffuuid not null
  • totalnumeric(10,2) not null
  • completed_attimestamptz
  • created_attimestamptz not null

sale_items

  • iduuid not null
  • sale_id> salesuuid not null
  • product_id> productsuuid not null
  • quantityinteger not null
  • pricenumeric(10,2) not null
  • discountnumeric(10,2) not null
  • created_attimestamptz not null

payments

  • iduuid not null
  • sale_id> salesuuid not null
  • methodtext not null
  • amountnumeric(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 "payments" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "sale_id" UUID NOT NULL,
  "method" TEXT NOT NULL,
  "amount" NUMERIC(10,2) 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,
  "barcode" TEXT UNIQUE,
  "price" NUMERIC(10,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "registers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "store_id" UUID NOT NULL,
  "label" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "sale_items" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "sale_id" UUID NOT NULL,
  "product_id" UUID NOT NULL,
  "quantity" INTEGER NOT NULL,
  "price" NUMERIC(10,2) NOT NULL,
  "discount" NUMERIC(10,2) DEFAULT 0 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "sales" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "register_id" UUID NOT NULL,
  "staff_id" UUID NOT NULL,
  "total" NUMERIC(10,2) NOT NULL,
  "completed_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "stores" (
  "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 "registers" ADD CONSTRAINT "fk_registers_store_id" FOREIGN KEY ("store_id") REFERENCES "stores" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "staff" ADD CONSTRAINT "fk_staff_store_id" FOREIGN KEY ("store_id") REFERENCES "stores" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "sales" ADD CONSTRAINT "fk_sales_register_id" FOREIGN KEY ("register_id") REFERENCES "registers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "sales" ADD CONSTRAINT "fk_sales_staff_id" FOREIGN KEY ("staff_id") REFERENCES "staff" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "sale_items" ADD CONSTRAINT "fk_sale_items_sale_id" FOREIGN KEY ("sale_id") REFERENCES "sales" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "sale_items" ADD CONSTRAINT "fk_sale_items_product_id" FOREIGN KEY ("product_id") REFERENCES "products" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "payments" ADD CONSTRAINT "fk_payments_sale_id" FOREIGN KEY ("sale_id") REFERENCES "sales" ("id") ON DELETE CASCADE 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.