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
- Double-entry accountingChart of accounts, journals and balanced journal entries per period.
- Banking coreCustomers, accounts, cards, transactions and transfers between accounts.
- Expense managementEmployees submit expense reports with receipts for policy checks and approval.
- Personal budgetingAccounts, categorised transactions and monthly budgets per category.
- Crypto walletUsers' wallets holding balances in assets, with on-chain transactions.
- Loan servicingBorrowers, loan products, loans with repayment schedules and payments.
- Insurance policiesPolicyholders, products, policies with coverages, premiums and claims.
- PayrollPay periods, payslips with earnings and deduction lines per employee.
- CrowdfundingCampaigns with reward tiers, backers' pledges and creator updates.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.