Templates/Finance

Invoicing database schema

Clients, invoices with line items and tax rates, and payments received.

5 tables, 4 relationships

Opens as a new diagram you can change. Free.

Tables

clients

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

tax_rates

  • iduuid not null
  • nametext not null
  • percentnumeric(5,2) not null
  • created_attimestamptz not null

invoices

  • iduuid not null
  • client_id> clientsuuid not null
  • numbertext not null
  • issued_ondate not null
  • due_ondate not null
  • statustext not null
  • created_attimestamptz not null

invoice_items

  • iduuid not null
  • invoice_id> invoicesuuid not null
  • tax_rate_id> tax_ratesuuid
  • descriptiontext not null
  • quantitynumeric(10,2) not null
  • unit_pricenumeric(10,2) not null
  • created_attimestamptz not null

invoice_payments

  • iduuid not null
  • invoice_id> invoicesuuid not null
  • amountnumeric(10,2) not null
  • received_ondate not null
  • methodtext 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 "clients" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "email" TEXT NOT NULL,
  "address" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "invoice_items" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "invoice_id" UUID NOT NULL,
  "tax_rate_id" UUID,
  "description" TEXT NOT NULL,
  "quantity" NUMERIC(10,2) NOT NULL,
  "unit_price" NUMERIC(10,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "invoice_payments" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "invoice_id" UUID NOT NULL,
  "amount" NUMERIC(10,2) NOT NULL,
  "received_on" DATE NOT NULL,
  "method" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "invoices" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "client_id" UUID NOT NULL,
  "number" TEXT NOT NULL UNIQUE,
  "issued_on" DATE NOT NULL,
  "due_on" DATE NOT NULL,
  "status" TEXT DEFAULT 'draft' NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "tax_rates" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "percent" NUMERIC(5,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "invoices" ADD CONSTRAINT "fk_invoices_client_id" FOREIGN KEY ("client_id") REFERENCES "clients" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "invoice_items" ADD CONSTRAINT "fk_invoice_items_invoice_id" FOREIGN KEY ("invoice_id") REFERENCES "invoices" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "invoice_items" ADD CONSTRAINT "fk_invoice_items_tax_rate_id" FOREIGN KEY ("tax_rate_id") REFERENCES "tax_rates" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;

ALTER TABLE "invoice_payments" ADD CONSTRAINT "fk_invoice_payments_invoice_id" FOREIGN KEY ("invoice_id") REFERENCES "invoices" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

More Finance templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.