Templates/Work & productivity

Time tracking database schema

Clients, projects and tasks with time entries that bill into invoices.

6 tables, 6 relationships

Opens as a new diagram you can change. Free.

Tables

users

  • iduuid not null
  • emailtext not null
  • hourly_ratenumeric(8,2) not null
  • created_attimestamptz not null

clients

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

projects

  • iduuid not null
  • client_id> clientsuuid not null
  • nametext not null
  • billableboolean not null
  • created_attimestamptz not null

project_tasks

  • iduuid not null
  • project_id> projectsuuid not null
  • nametext not null
  • created_attimestamptz not null

invoices

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

time_entries

  • iduuid not null
  • user_id> usersuuid not null
  • task_id> project_tasksuuid not null
  • invoice_id> invoicesuuid
  • started_attimestamptz not null
  • minutesinteger not null
  • notestext
  • 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,
  "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,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "projects" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "client_id" UUID NOT NULL,
  "name" TEXT NOT NULL,
  "billable" BOOLEAN DEFAULT true NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "time_entries" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "user_id" UUID NOT NULL,
  "task_id" UUID NOT NULL,
  "invoice_id" UUID,
  "started_at" TIMESTAMPTZ NOT NULL,
  "minutes" INTEGER NOT NULL,
  "notes" TEXT,
  "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,
  "hourly_rate" NUMERIC(8,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

ALTER TABLE "project_tasks" ADD CONSTRAINT "fk_project_tasks_project_id" FOREIGN KEY ("project_id") REFERENCES "projects" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

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 "time_entries" ADD CONSTRAINT "fk_time_entries_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "time_entries" ADD CONSTRAINT "fk_time_entries_task_id" FOREIGN KEY ("task_id") REFERENCES "project_tasks" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "time_entries" ADD CONSTRAINT "fk_time_entries_invoice_id" FOREIGN KEY ("invoice_id") REFERENCES "invoices" ("id") ON DELETE SET NULL 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.