Templates/Commerce

Auctions database schema

Auctions with lots, timed bids, watchers and winners.

5 tables, 7 relationships

Opens as a new diagram you can change. Free.

Tables

users

  • iduuid not null
  • emailtext not null
  • display_nametext not null
  • created_attimestamptz not null

auctions

  • iduuid not null
  • titletext not null
  • starts_attimestamptz not null
  • ends_attimestamptz not null
  • created_attimestamptz not null

lots

  • iduuid not null
  • auction_id> auctionsuuid not null
  • seller_id> usersuuid not null
  • titletext not null
  • reserve_pricenumeric(10,2)
  • winner_id> usersuuid
  • created_attimestamptz not null

bids

  • iduuid not null
  • lot_id> lotsuuid not null
  • bidder_id> usersuuid not null
  • amountnumeric(10,2) not null
  • placed_attimestamptz not null
  • created_attimestamptz not null

watchers

  • iduuid not null
  • lot_id> lotsuuid not null
  • user_id> usersuuid 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 "auctions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "title" TEXT NOT NULL,
  "starts_at" TIMESTAMPTZ NOT NULL,
  "ends_at" TIMESTAMPTZ NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "bids" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "lot_id" UUID NOT NULL,
  "bidder_id" UUID NOT NULL,
  "amount" NUMERIC(10,2) NOT NULL,
  "placed_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "lots" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "auction_id" UUID NOT NULL,
  "seller_id" UUID NOT NULL,
  "title" TEXT NOT NULL,
  "reserve_price" NUMERIC(10,2),
  "winner_id" UUID,
  "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,
  "display_name" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "watchers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "lot_id" UUID NOT NULL,
  "user_id" UUID NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "lots" ADD CONSTRAINT "fk_lots_auction_id" FOREIGN KEY ("auction_id") REFERENCES "auctions" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "lots" ADD CONSTRAINT "fk_lots_seller_id" FOREIGN KEY ("seller_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "lots" ADD CONSTRAINT "fk_lots_winner_id" FOREIGN KEY ("winner_id") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;

ALTER TABLE "bids" ADD CONSTRAINT "fk_bids_lot_id" FOREIGN KEY ("lot_id") REFERENCES "lots" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "bids" ADD CONSTRAINT "fk_bids_bidder_id" FOREIGN KEY ("bidder_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "watchers" ADD CONSTRAINT "fk_watchers_lot_id" FOREIGN KEY ("lot_id") REFERENCES "lots" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "watchers" ADD CONSTRAINT "fk_watchers_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("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.