Templates/Finance

Expense management database schema

Employees submit expense reports with receipts for policy checks and approval.

6 tables, 7 relationships

Opens as a new diagram you can change. Free.

Tables

employees

  • iduuid not null
  • nametext not null
  • emailtext not null
  • approver_id> employeesuuid
  • created_attimestamptz not null

expense_policies

  • iduuid not null
  • categorytext not null
  • max_amountnumeric(10,2) not null
  • created_attimestamptz not null

expense_reports

  • iduuid not null
  • employee_id> employeesuuid not null
  • titletext not null
  • statustext not null
  • submitted_attimestamptz
  • created_attimestamptz not null

expenses

  • iduuid not null
  • report_id> expense_reportsuuid not null
  • policy_id> expense_policiesuuid
  • amountnumeric(10,2) not null
  • merchanttext not null
  • spent_ondate not null
  • created_attimestamptz not null

receipts

  • iduuid not null
  • expense_id> expensesuuid not null
  • file_urltext not null
  • created_attimestamptz not null

approvals

  • iduuid not null
  • report_id> expense_reportsuuid not null
  • approver_id> employeesuuid not null
  • approvedboolean not null
  • commenttext
  • 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 "approvals" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "report_id" UUID NOT NULL,
  "approver_id" UUID NOT NULL,
  "approved" BOOLEAN NOT NULL,
  "comment" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "expense_policies" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "category" TEXT NOT NULL,
  "max_amount" NUMERIC(10,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "expense_reports" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "employee_id" UUID NOT NULL,
  "title" TEXT NOT NULL,
  "status" TEXT DEFAULT 'draft' NOT NULL,
  "submitted_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "expenses" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "report_id" UUID NOT NULL,
  "policy_id" UUID,
  "amount" NUMERIC(10,2) NOT NULL,
  "merchant" TEXT NOT NULL,
  "spent_on" DATE NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "receipts" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "expense_id" UUID NOT NULL,
  "file_url" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "employees" ADD CONSTRAINT "fk_employees_approver_id" FOREIGN KEY ("approver_id") REFERENCES "employees" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;

ALTER TABLE "expense_reports" ADD CONSTRAINT "fk_expense_reports_employee_id" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "expenses" ADD CONSTRAINT "fk_expenses_report_id" FOREIGN KEY ("report_id") REFERENCES "expense_reports" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "expenses" ADD CONSTRAINT "fk_expenses_policy_id" FOREIGN KEY ("policy_id") REFERENCES "expense_policies" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;

ALTER TABLE "receipts" ADD CONSTRAINT "fk_receipts_expense_id" FOREIGN KEY ("expense_id") REFERENCES "expenses" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "approvals" ADD CONSTRAINT "fk_approvals_report_id" FOREIGN KEY ("report_id") REFERENCES "expense_reports" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "approvals" ADD CONSTRAINT "fk_approvals_approver_id" FOREIGN KEY ("approver_id") REFERENCES "employees" ("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.