Templates/Work & productivity

HR & people database schema

Employees in departments and positions, reporting lines, leave and salary history.

6 tables, 7 relationships

Opens as a new diagram you can change. Free.

Tables

departments

  • iduuid not null
  • nametext not null
  • parent_id> departmentsuuid
  • created_attimestamptz not null

positions

  • iduuid not null
  • titletext not null
  • leveltext
  • created_attimestamptz not null

employees

  • iduuid not null
  • department_id> departmentsuuid not null
  • position_id> positionsuuid not null
  • manager_id> employeesuuid
  • first_nametext not null
  • last_nametext not null
  • emailtext not null
  • started_ondate not null
  • created_attimestamptz not null

leave_types

  • iduuid not null
  • nametext not null
  • days_per_yearinteger not null
  • created_attimestamptz not null

leave_requests

  • iduuid not null
  • employee_id> employeesuuid not null
  • leave_type_id> leave_typesuuid not null
  • starts_ondate not null
  • ends_ondate not null
  • statustext not null
  • created_attimestamptz not null

salaries

  • iduuid not null
  • employee_id> employeesuuid not null
  • amountnumeric(12,2) not null
  • currencytext not null
  • effective_ondate 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 "departments" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "parent_id" UUID,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "employees" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "department_id" UUID NOT NULL,
  "position_id" UUID NOT NULL,
  "manager_id" UUID,
  "first_name" TEXT NOT NULL,
  "last_name" TEXT NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "started_on" DATE NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "leave_requests" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "employee_id" UUID NOT NULL,
  "leave_type_id" UUID NOT NULL,
  "starts_on" DATE NOT NULL,
  "ends_on" DATE NOT NULL,
  "status" TEXT DEFAULT 'pending' NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "leave_types" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "days_per_year" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "positions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "title" TEXT NOT NULL,
  "level" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "salaries" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "employee_id" UUID NOT NULL,
  "amount" NUMERIC(12,2) NOT NULL,
  "currency" TEXT DEFAULT 'gbp' NOT NULL,
  "effective_on" DATE NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "departments" ADD CONSTRAINT "fk_departments_parent_id" FOREIGN KEY ("parent_id") REFERENCES "departments" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;

ALTER TABLE "employees" ADD CONSTRAINT "fk_employees_department_id" FOREIGN KEY ("department_id") REFERENCES "departments" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "employees" ADD CONSTRAINT "fk_employees_position_id" FOREIGN KEY ("position_id") REFERENCES "positions" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

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

ALTER TABLE "leave_requests" ADD CONSTRAINT "fk_leave_requests_employee_id" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "leave_requests" ADD CONSTRAINT "fk_leave_requests_leave_type_id" FOREIGN KEY ("leave_type_id") REFERENCES "leave_types" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "salaries" ADD CONSTRAINT "fk_salaries_employee_id" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

More Work & productivity templates

Start with one diagram, free

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