Templates/Content & media

Email newsletter database schema

Publications, subscribers, issues and per-send open and click tracking.

6 tables, 6 relationships

Opens as a new diagram you can change. Free.

Tables

publications

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

subscribers

  • iduuid not null
  • publication_id> publicationsuuid not null
  • emailtext not null
  • confirmed_attimestamptz
  • unsubscribed_attimestamptz
  • created_attimestamptz not null

issues

  • iduuid not null
  • publication_id> publicationsuuid not null
  • subjecttext not null
  • body_htmltext not null
  • sent_attimestamptz
  • created_attimestamptz not null

sends

  • iduuid not null
  • issue_id> issuesuuid not null
  • subscriber_id> subscribersuuid not null
  • deliveredboolean not null
  • created_attimestamptz not null

opens

  • iduuid not null
  • send_id> sendsuuid not null
  • opened_attimestamptz not null
  • created_attimestamptz not null

clicks

  • iduuid not null
  • send_id> sendsuuid not null
  • urltext not null
  • clicked_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 "clicks" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "send_id" UUID NOT NULL,
  "url" TEXT NOT NULL,
  "clicked_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "issues" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "publication_id" UUID NOT NULL,
  "subject" TEXT NOT NULL,
  "body_html" TEXT NOT NULL,
  "sent_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "opens" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "send_id" UUID NOT NULL,
  "opened_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "sends" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "issue_id" UUID NOT NULL,
  "subscriber_id" UUID NOT NULL,
  "delivered" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "subscribers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "publication_id" UUID NOT NULL,
  "email" TEXT NOT NULL,
  "confirmed_at" TIMESTAMPTZ,
  "unsubscribed_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "subscribers" ADD CONSTRAINT "fk_subscribers_publication_id" FOREIGN KEY ("publication_id") REFERENCES "publications" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "issues" ADD CONSTRAINT "fk_issues_publication_id" FOREIGN KEY ("publication_id") REFERENCES "publications" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "sends" ADD CONSTRAINT "fk_sends_issue_id" FOREIGN KEY ("issue_id") REFERENCES "issues" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "sends" ADD CONSTRAINT "fk_sends_subscriber_id" FOREIGN KEY ("subscriber_id") REFERENCES "subscribers" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "opens" ADD CONSTRAINT "fk_opens_send_id" FOREIGN KEY ("send_id") REFERENCES "sends" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "clicks" ADD CONSTRAINT "fk_clicks_send_id" FOREIGN KEY ("send_id") REFERENCES "sends" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

More Content & media templates

Start with one diagram, free

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