Templates/Work & productivity

Projects & tasks database schema

Workspaces, projects and tasks with assignees, labels and comments.

8 tables, 10 relationships

Opens as a new diagram you can change. Free.

Tables

workspaces

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

users

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

projects

  • iduuid not null
  • workspace_id> workspacesuuid not null
  • nametext not null
  • keytext not null
  • archivedboolean not null
  • created_attimestamptz not null

tasks

  • iduuid not null
  • project_id> projectsuuid not null
  • parent_id> tasksuuid
  • titletext not null
  • descriptiontext
  • statustask_status not null
  • due_ondate
  • created_attimestamptz not null

task_assignees

  • iduuid not null
  • task_id> tasksuuid not null
  • user_id> usersuuid not null
  • created_attimestamptz not null

labels

  • iduuid not null
  • workspace_id> workspacesuuid not null
  • nametext not null
  • colortext not null
  • created_attimestamptz not null

task_labels

  • iduuid not null
  • task_id> tasksuuid not null
  • label_id> labelsuuid not null
  • created_attimestamptz not null

task_comments

  • iduuid not null
  • task_id> tasksuuid not null
  • author_id> usersuuid not null
  • bodytext 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 TYPE "task_status" AS ENUM ('todo', 'in_progress', 'in_review', 'done');

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

CREATE TABLE "projects" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "workspace_id" UUID NOT NULL,
  "name" TEXT NOT NULL,
  "key" TEXT NOT NULL,
  "archived" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "task_assignees" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "task_id" UUID NOT NULL,
  "user_id" UUID NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "task_comments" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "task_id" UUID NOT NULL,
  "author_id" UUID NOT NULL,
  "body" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "task_labels" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "task_id" UUID NOT NULL,
  "label_id" UUID NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "tasks" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "project_id" UUID NOT NULL,
  "parent_id" UUID,
  "title" TEXT NOT NULL,
  "description" TEXT,
  "status" "task_status" DEFAULT 'todo' NOT NULL,
  "due_on" DATE,
  "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,
  "name" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

ALTER TABLE "projects" ADD CONSTRAINT "fk_projects_workspace_id" FOREIGN KEY ("workspace_id") REFERENCES "workspaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

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

ALTER TABLE "tasks" ADD CONSTRAINT "fk_tasks_parent_id" FOREIGN KEY ("parent_id") REFERENCES "tasks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "task_assignees" ADD CONSTRAINT "fk_task_assignees_task_id" FOREIGN KEY ("task_id") REFERENCES "tasks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "task_assignees" ADD CONSTRAINT "fk_task_assignees_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "labels" ADD CONSTRAINT "fk_labels_workspace_id" FOREIGN KEY ("workspace_id") REFERENCES "workspaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "task_labels" ADD CONSTRAINT "fk_task_labels_task_id" FOREIGN KEY ("task_id") REFERENCES "tasks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "task_labels" ADD CONSTRAINT "fk_task_labels_label_id" FOREIGN KEY ("label_id") REFERENCES "labels" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "task_comments" ADD CONSTRAINT "fk_task_comments_task_id" FOREIGN KEY ("task_id") REFERENCES "tasks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "task_comments" ADD CONSTRAINT "fk_task_comments_author_id" FOREIGN KEY ("author_id") REFERENCES "users" ("id") ON DELETE NO ACTION 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.