Templates/Content & media

Video streaming database schema

Titles with seasons and episodes, viewer profiles, watch history and ratings.

7 tables, 8 relationships

Opens as a new diagram you can change. Free.

Tables

accounts

  • iduuid not null
  • emailtext not null
  • plantext not null
  • created_attimestamptz not null

profiles

  • iduuid not null
  • account_id> accountsuuid not null
  • nametext not null
  • kidsboolean not null
  • created_attimestamptz not null

titles

  • iduuid not null
  • nametext not null
  • kindtext not null
  • release_yearinteger
  • maturity_ratingtext
  • created_attimestamptz not null

seasons

  • iduuid not null
  • title_id> titlesuuid not null
  • numberinteger not null
  • created_attimestamptz not null

episodes

  • iduuid not null
  • season_id> seasonsuuid not null
  • numberinteger not null
  • nametext not null
  • duration_secondsinteger not null
  • created_attimestamptz not null

watch_history

  • iduuid not null
  • profile_id> profilesuuid not null
  • title_id> titlesuuid not null
  • episode_id> episodesuuid
  • position_secondsinteger not null
  • created_attimestamptz not null

ratings

  • iduuid not null
  • profile_id> profilesuuid not null
  • title_id> titlesuuid not null
  • thumbs_upboolean 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 "accounts" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "plan" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "episodes" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "season_id" UUID NOT NULL,
  "number" INTEGER NOT NULL,
  "name" TEXT NOT NULL,
  "duration_seconds" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "profiles" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "account_id" UUID NOT NULL,
  "name" TEXT NOT NULL,
  "kids" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "ratings" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "profile_id" UUID NOT NULL,
  "title_id" UUID NOT NULL,
  "thumbs_up" BOOLEAN NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "seasons" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "title_id" UUID NOT NULL,
  "number" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "titles" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "kind" TEXT NOT NULL,
  "release_year" INTEGER,
  "maturity_rating" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "watch_history" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "profile_id" UUID NOT NULL,
  "title_id" UUID NOT NULL,
  "episode_id" UUID,
  "position_seconds" INTEGER DEFAULT 0 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "profiles" ADD CONSTRAINT "fk_profiles_account_id" FOREIGN KEY ("account_id") REFERENCES "accounts" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "seasons" ADD CONSTRAINT "fk_seasons_title_id" FOREIGN KEY ("title_id") REFERENCES "titles" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "episodes" ADD CONSTRAINT "fk_episodes_season_id" FOREIGN KEY ("season_id") REFERENCES "seasons" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "watch_history" ADD CONSTRAINT "fk_watch_history_profile_id" FOREIGN KEY ("profile_id") REFERENCES "profiles" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "watch_history" ADD CONSTRAINT "fk_watch_history_title_id" FOREIGN KEY ("title_id") REFERENCES "titles" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "watch_history" ADD CONSTRAINT "fk_watch_history_episode_id" FOREIGN KEY ("episode_id") REFERENCES "episodes" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "ratings" ADD CONSTRAINT "fk_ratings_profile_id" FOREIGN KEY ("profile_id") REFERENCES "profiles" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "ratings" ADD CONSTRAINT "fk_ratings_title_id" FOREIGN KEY ("title_id") REFERENCES "titles" ("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.