Wiki / knowledge base database schema
Spaces of nested pages with revisions, attachments and links between pages.
6 tables, 7 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
spaces
- iduuid not null
- keytext not null
- nametext not null
- created_attimestamptz not null
pages
- iduuid not null
- space_id> spacesuuid not null
- parent_id> pagesuuid
- titletext not null
- slugtext not null
- created_attimestamptz not null
page_revisions
- iduuid not null
- page_id> pagesuuid not null
- author_id> usersuuid not null
- bodytext not null
- revisioninteger not null
- created_attimestamptz not null
attachments
- iduuid not null
- page_id> pagesuuid not null
- filenametext not null
- urltext not null
- created_attimestamptz not null
page_links
- iduuid not null
- from_page_id> pagesuuid not null
- to_page_id> pagesuuid 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 "attachments" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"page_id" UUID NOT NULL,
"filename" TEXT NOT NULL,
"url" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "page_links" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"from_page_id" UUID NOT NULL,
"to_page_id" UUID NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "page_revisions" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"page_id" UUID NOT NULL,
"author_id" UUID NOT NULL,
"body" TEXT NOT NULL,
"revision" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "pages" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"space_id" UUID NOT NULL,
"parent_id" UUID,
"title" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "spaces" (
"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 "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 "pages" ADD CONSTRAINT "fk_pages_space_id" FOREIGN KEY ("space_id") REFERENCES "spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "pages" ADD CONSTRAINT "fk_pages_parent_id" FOREIGN KEY ("parent_id") REFERENCES "pages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "page_revisions" ADD CONSTRAINT "fk_page_revisions_page_id" FOREIGN KEY ("page_id") REFERENCES "pages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "page_revisions" ADD CONSTRAINT "fk_page_revisions_author_id" FOREIGN KEY ("author_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "attachments" ADD CONSTRAINT "fk_attachments_page_id" FOREIGN KEY ("page_id") REFERENCES "pages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "page_links" ADD CONSTRAINT "fk_page_links_from_page_id" FOREIGN KEY ("from_page_id") REFERENCES "pages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "page_links" ADD CONSTRAINT "fk_page_links_to_page_id" FOREIGN KEY ("to_page_id") REFERENCES "pages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;More Content & media templates
- Blog / CMSAuthors, posts, categories (many-to-many) and threaded comments.
- Headless CMSContent types with fields, localised entries, versions and assets.
- News publicationSections, articles with several authors, tags and corrections.
- Podcast hostingShows, episodes, hosts and download stats.
- Video streamingTitles with seasons and episodes, viewer profiles, watch history and ratings.
- Music streamingArtists, albums and tracks, listener playlists and play counts.
- Photo sharingAlbums of photos with tags, likes and comments.
- Email newsletterPublications, subscribers, issues and per-send open and click tracking.
- Digital asset managementAssets in folders with renditions, collections and usage licences.
- Blog with comments (MongoDB)Authors, posts with embedded tags and SEO fields, comments by reference, and sessions that expire.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.