CRM database schema
Companies, contacts, deals moving through pipeline stages, and activities.
7 tables, 9 relationships
Opens as a new diagram you can change. Free.
Tables
users
- iduuid not null
- emailtext not null
- nametext not null
- created_attimestamptz not null
companies
- iduuid not null
- nametext not null
- domaintext
- industrytext
- owner_id> usersuuid
- created_attimestamptz not null
contacts
- iduuid not null
- company_id> companiesuuid
- first_nametext not null
- last_nametext not null
- emailtext
- phonetext
- created_attimestamptz not null
pipelines
- iduuid not null
- nametext not null
- created_attimestamptz not null
stages
- iduuid not null
- pipeline_id> pipelinesuuid not null
- nametext not null
- positioninteger not null
- win_probabilityinteger not null
- created_attimestamptz not null
deals
- iduuid not null
- company_id> companiesuuid not null
- stage_id> stagesuuid not null
- owner_id> usersuuid not null
- titletext not null
- valuenumeric(12,2) not null
- close_ondate
- created_attimestamptz not null
activities
- iduuid not null
- deal_id> dealsuuid
- contact_id> contactsuuid
- author_id> usersuuid not null
- kindtext not null
- notestext
- occurred_attimestamptz 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 "activities" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"deal_id" UUID,
"contact_id" UUID,
"author_id" UUID NOT NULL,
"kind" TEXT NOT NULL,
"notes" TEXT,
"occurred_at" TIMESTAMPTZ NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "companies" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"domain" TEXT,
"industry" TEXT,
"owner_id" UUID,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "contacts" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"company_id" UUID,
"first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"email" TEXT,
"phone" TEXT,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "deals" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"company_id" UUID NOT NULL,
"stage_id" UUID NOT NULL,
"owner_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"value" NUMERIC(12,2) NOT NULL,
"close_on" DATE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "pipelines" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "stages" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"pipeline_id" UUID NOT NULL,
"name" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"win_probability" INTEGER DEFAULT 0 NOT NULL,
"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")
);
ALTER TABLE "companies" ADD CONSTRAINT "fk_companies_owner_id" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;
ALTER TABLE "contacts" ADD CONSTRAINT "fk_contacts_company_id" FOREIGN KEY ("company_id") REFERENCES "companies" ("id") ON DELETE SET NULL ON UPDATE NO ACTION;
ALTER TABLE "stages" ADD CONSTRAINT "fk_stages_pipeline_id" FOREIGN KEY ("pipeline_id") REFERENCES "pipelines" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "deals" ADD CONSTRAINT "fk_deals_company_id" FOREIGN KEY ("company_id") REFERENCES "companies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "deals" ADD CONSTRAINT "fk_deals_stage_id" FOREIGN KEY ("stage_id") REFERENCES "stages" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "deals" ADD CONSTRAINT "fk_deals_owner_id" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "activities" ADD CONSTRAINT "fk_activities_deal_id" FOREIGN KEY ("deal_id") REFERENCES "deals" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "activities" ADD CONSTRAINT "fk_activities_contact_id" FOREIGN KEY ("contact_id") REFERENCES "contacts" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "activities" ADD CONSTRAINT "fk_activities_author_id" FOREIGN KEY ("author_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;More Work & productivity templates
- Projects & tasksWorkspaces, projects and tasks with assignees, labels and comments.
- Kanban boardBoards with columns of cards, members and checklists.
- Help deskCustomer tickets, threaded messages, agents, SLA policies and tags.
- HR & peopleEmployees in departments and positions, reporting lines, leave and salary history.
- Applicant trackingJob openings, candidates, applications through stages, interviews and scorecards.
- Time trackingClients, projects and tasks with time entries that bill into invoices.
- Calendar & schedulingCalendars, events with attendees, recurrence rules and reminders.
- OKRs & goalsTeams set objectives with measurable key results and regular check-ins.
- Document e-signatureDocuments sent to signers, signature fields, signatures and an audit trail.
- Task lists (Firestore)Workspaces, their projects and tasks, with due-date queries indexed and finished tasks expiring.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.