53 lines
1.8 KiB
SQL
53 lines
1.8 KiB
SQL
CREATE TABLE IF NOT EXISTS artists (
|
|
id text NOT NULL,
|
|
name text,
|
|
website text
|
|
);
|
|
ALTER TABLE artists ADD CONSTRAINT artists_pk PRIMARY KEY (id);
|
|
|
|
CREATE TABLE IF NOT EXISTS musicreleases (
|
|
id character varying(64) NOT NULL,
|
|
title text NOT NULL,
|
|
type text,
|
|
release_date DATE NOT NULL,
|
|
artwork text,
|
|
buyname text,
|
|
buylink text
|
|
);
|
|
ALTER TABLE musicreleases ADD CONSTRAINT musicreleases_pk PRIMARY KEY (id);
|
|
|
|
CREATE TABLE IF NOT EXISTS musiclinks (
|
|
release character varying(64) NOT NULL,
|
|
name text NOT NULL,
|
|
url text,
|
|
);
|
|
ALTER TABLE musiclinks ADD CONSTRAINT musiclinks_pk PRIMARY KEY (release, name);
|
|
|
|
CREATE TABLE IF NOT EXISTS musiccredits (
|
|
release character varying(64) NOT NULL,
|
|
artist text NOT NULL,
|
|
role text,
|
|
is_primary boolean,
|
|
);
|
|
ALTER TABLE musiccredits ADD CONSTRAINT musiccredits_pk PRIMARY KEY (release, artist);
|
|
|
|
CREATE TABLE IF NOT EXISTS musictracks (
|
|
release character varying(64) NOT NULL,
|
|
number integer NOT NULL,
|
|
title text NOT NULL,
|
|
description text,
|
|
lyrics text,
|
|
preview_url text,
|
|
);
|
|
ALTER TABLE musictracks ADD CONSTRAINT musictracks_pk PRIMARY KEY (release, number);
|
|
|
|
-- 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 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.musictracks ADD CONSTRAINT musictracks_release_fk FOREIGN KEY (release) REFERENCES public.musicreleases(id) ON DELETE CASCADE;
|