Templates/Content & media

Headless CMS database schema

Content types with fields, localised entries, versions and assets.

6 tables, 4 relationships

Opens as a new diagram you can change. Free.

Tables

content_types

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

fields

  • iduuid not null
  • content_type_id> content_typesuuid not null
  • keytext not null
  • kindtext not null
  • requiredboolean not null
  • positioninteger not null
  • created_attimestamptz not null

locales

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

entries

  • iduuid not null
  • content_type_id> content_typesuuid not null
  • slugtext
  • published_attimestamptz
  • created_attimestamptz not null

entry_versions

  • iduuid not null
  • entry_id> entriesuuid not null
  • locale_id> localesuuid not null
  • datajsonb not null
  • versioninteger not null
  • created_attimestamptz not null

assets

  • iduuid not null
  • filenametext not null
  • mime_typetext not null
  • urltext not null
  • size_bytesbigint 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 "assets" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "filename" TEXT NOT NULL,
  "mime_type" TEXT NOT NULL,
  "url" TEXT NOT NULL,
  "size_bytes" BIGINT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "entries" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "content_type_id" UUID NOT NULL,
  "slug" TEXT,
  "published_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "entry_versions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "entry_id" UUID NOT NULL,
  "locale_id" UUID NOT NULL,
  "data" JSONB NOT NULL,
  "version" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "fields" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "content_type_id" UUID NOT NULL,
  "key" TEXT NOT NULL,
  "kind" TEXT NOT NULL,
  "required" BOOLEAN DEFAULT false NOT NULL,
  "position" INTEGER DEFAULT 0 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

ALTER TABLE "fields" ADD CONSTRAINT "fk_fields_content_type_id" FOREIGN KEY ("content_type_id") REFERENCES "content_types" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "entries" ADD CONSTRAINT "fk_entries_content_type_id" FOREIGN KEY ("content_type_id") REFERENCES "content_types" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "entry_versions" ADD CONSTRAINT "fk_entry_versions_entry_id" FOREIGN KEY ("entry_id") REFERENCES "entries" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "entry_versions" ADD CONSTRAINT "fk_entry_versions_locale_id" FOREIGN KEY ("locale_id") REFERENCES "locales" ("id") ON DELETE NO ACTION 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.