refactoring everything teehee (i'm so glad this isn't a team project)

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-08-01 01:39:18 +01:00
parent c684f0c7ae
commit 10f5f51e76
17 changed files with 970 additions and 547 deletions

View file

@ -1,3 +1,6 @@
--
-- Artists (should be applicable to all art)
--
CREATE TABLE IF NOT EXISTS artists (
id text NOT NULL,
name text,
@ -5,9 +8,13 @@ CREATE TABLE IF NOT EXISTS artists (
);
ALTER TABLE artists ADD CONSTRAINT artists_pk PRIMARY KEY (id);
--
-- Music releases
--
CREATE TABLE IF NOT EXISTS musicreleases (
id character varying(64) NOT NULL,
title text NOT NULL,
description text,
type text,
release_date DATE NOT NULL,
artwork text,
@ -16,6 +23,9 @@ CREATE TABLE IF NOT EXISTS musicreleases (
);
ALTER TABLE musicreleases ADD CONSTRAINT musicreleases_pk PRIMARY KEY (id);
--
-- Music links (external platform links under a release)
--
CREATE TABLE IF NOT EXISTS musiclinks (
release character varying(64) NOT NULL,
name text NOT NULL,
@ -23,6 +33,9 @@ CREATE TABLE IF NOT EXISTS musiclinks (
);
ALTER TABLE musiclinks ADD CONSTRAINT musiclinks_pk PRIMARY KEY (release, name);
--
-- Music credits (artist credits under a release)
--
CREATE TABLE IF NOT EXISTS musiccredits (
release character varying(64) NOT NULL,
artist text NOT NULL,
@ -31,6 +44,9 @@ CREATE TABLE IF NOT EXISTS musiccredits (
);
ALTER TABLE musiccredits ADD CONSTRAINT musiccredits_pk PRIMARY KEY (release, artist);
--
-- Music tracks (tracks under a release)
--
CREATE TABLE IF NOT EXISTS musictracks (
release character varying(64) NOT NULL,
number integer NOT NULL,
@ -41,12 +57,14 @@ CREATE TABLE IF NOT EXISTS musictracks (
);
ALTER TABLE musictracks ADD CONSTRAINT musictracks_pk PRIMARY KEY (release, number);
-- foreign keys
--
-- Foreign keys
--
ALTER TABLE public.musiccredits ADD CONSTRAINT musiccredits_artist_fk FOREIGN KEY (artist) REFERENCES public.artists(id) ON DELETE CASCADE;
ALTER TABLE public.musiccredits ADD CONSTRAINT IF NOT EXISTS musiccredits_artist_fk FOREIGN KEY (artist) REFERENCES public.artists(id) ON DELETE CASCADE;
ALTER TABLE public.musiccredits ADD CONSTRAINT musiccredits_release_fk FOREIGN KEY (release) REFERENCES public.musicreleases(id) ON DELETE CASCADE;
ALTER TABLE public.musiccredits ADD CONSTRAINT IF NOT EXISTS musiccredits_release_fk FOREIGN KEY (release) REFERENCES public.musicreleases(id) ON DELETE CASCADE;
ALTER TABLE public.musiclinks ADD CONSTRAINT musiclinks_release_fk FOREIGN KEY (release) REFERENCES public.musicreleases(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE public.musiclinks ADD CONSTRAINT IF NOT EXISTS musiclinks_release_fk FOREIGN KEY (release) REFERENCES public.musicreleases(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE public.musictracks ADD CONSTRAINT musictracks_release_fk FOREIGN KEY (release) REFERENCES public.musicreleases(id) ON DELETE CASCADE;
ALTER TABLE public.musictracks ADD CONSTRAINT IF NOT EXISTS musictracks_release_fk FOREIGN KEY (release) REFERENCES public.musicreleases(id) ON DELETE CASCADE;