organizations
The customer account (tenant) that owns projects.
Most SaaS products follow this shape: a customer account (the organization), the people who belong to it, and the work they do. This is a common starting point for task trackers, CRMs, and team tools.
The customer account (tenant) that owns projects.
People with a login.
Which users belong to which organizations, and in what role. A junction table.
Containers of work, owned by an organization.
Units of work in a project, optionally assigned to a user.
memberships is a junction table between organizations and users: many-to-many.projects.organization_id references organizations.id: one row in organizations can have many rows in projects.tasks.project_id references projects.id: one row in projects can have many rows in tasks.tasks.assignee_id references users.id: one row in users can have many rows in tasks.Copy it into your database, or open it in Crowsfoot to edit the diagram, add notes, and export again.
CREATE TABLE organizations (
id bigint PRIMARY KEY,
name varchar(120) NOT NULL,
plan varchar(20) NOT NULL DEFAULT 'free'
);
CREATE TABLE users (
id bigint PRIMARY KEY,
email varchar(255) NOT NULL,
name varchar(120) NOT NULL
);
CREATE TABLE memberships (
organization_id bigint NOT NULL REFERENCES organizations (id),
user_id bigint NOT NULL REFERENCES users (id),
role varchar(20) NOT NULL DEFAULT 'member',
PRIMARY KEY (organization_id, user_id)
);
CREATE TABLE projects (
id bigint PRIMARY KEY,
organization_id bigint NOT NULL REFERENCES organizations (id),
name varchar(160) NOT NULL,
archived boolean NOT NULL DEFAULT false
);
CREATE TABLE tasks (
id bigint PRIMARY KEY,
project_id bigint NOT NULL REFERENCES projects (id),
assignee_id bigint REFERENCES users (id),
title varchar(200) NOT NULL,
status varchar(20) NOT NULL DEFAULT 'todo',
due_on date
);
New to ER diagrams? Read the crow’s foot notation guide.