Music streaming database schema
Artists, albums and tracks, listener playlists and play counts.
7 tables, 7 relationships
Opens as a new diagram you can change. Free.
Tables
artists
- iduuid not null
- nametext not null
- created_attimestamptz not null
albums
- iduuid not null
- artist_id> artistsuuid not null
- titletext not null
- released_ondate
- created_attimestamptz not null
tracks
- iduuid not null
- album_id> albumsuuid not null
- titletext not null
- duration_secondsinteger not null
- track_numberinteger not null
- created_attimestamptz not null
listeners
- iduuid not null
- emailtext not null
- display_nametext not null
- created_attimestamptz not null
playlists
- iduuid not null
- owner_id> listenersuuid not null
- nametext not null
- publicboolean not null
- created_attimestamptz not null
playlist_tracks
- iduuid not null
- playlist_id> playlistsuuid not null
- track_id> tracksuuid not null
- positioninteger not null
- created_attimestamptz not null
plays
- iduuid not null
- listener_id> listenersuuid not null
- track_id> tracksuuid not null
- played_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 "albums" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"artist_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"released_on" DATE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "artists" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "listeners" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"email" TEXT NOT NULL UNIQUE,
"display_name" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "playlist_tracks" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"playlist_id" UUID NOT NULL,
"track_id" UUID NOT NULL,
"position" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "playlists" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"owner_id" UUID NOT NULL,
"name" TEXT NOT NULL,
"public" BOOLEAN DEFAULT false NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "plays" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"listener_id" UUID NOT NULL,
"track_id" UUID NOT NULL,
"played_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "tracks" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"album_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"duration_seconds" INTEGER NOT NULL,
"track_number" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "albums" ADD CONSTRAINT "fk_albums_artist_id" FOREIGN KEY ("artist_id") REFERENCES "artists" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "tracks" ADD CONSTRAINT "fk_tracks_album_id" FOREIGN KEY ("album_id") REFERENCES "albums" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "playlists" ADD CONSTRAINT "fk_playlists_owner_id" FOREIGN KEY ("owner_id") REFERENCES "listeners" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "playlist_tracks" ADD CONSTRAINT "fk_playlist_tracks_playlist_id" FOREIGN KEY ("playlist_id") REFERENCES "playlists" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "playlist_tracks" ADD CONSTRAINT "fk_playlist_tracks_track_id" FOREIGN KEY ("track_id") REFERENCES "tracks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "plays" ADD CONSTRAINT "fk_plays_listener_id" FOREIGN KEY ("listener_id") REFERENCES "listeners" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "plays" ADD CONSTRAINT "fk_plays_track_id" FOREIGN KEY ("track_id") REFERENCES "tracks" ("id") ON DELETE NO ACTION 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.
- Photo sharingAlbums of photos with tags, likes and comments.
- Wiki / knowledge baseSpaces of nested pages with revisions, attachments and links between pages.
- 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.