arimelody.me/schema.sql

81 lines
2.4 KiB
MySQL
Raw Normal View History

--
-- Artists (should be applicable to all art)
--
2024-11-10 00:18:52 +00:00
CREATE TABLE artist (
id character varying(64),
name text NOT NULL,
website text,
avatar text
);
2024-11-10 00:18:52 +00:00
ALTER TABLE artist ADD CONSTRAINT artist_pk PRIMARY KEY (id);
--
-- Music releases
--
2024-11-10 00:18:52 +00:00
CREATE TABLE musicrelease (
id character varying(64) NOT NULL,
visible bool DEFAULT false,
title text NOT NULL,
description text,
type text,
release_date TIMESTAMP NOT NULL,
artwork text,
buyname text,
buylink text,
copyright text,
copyrightURL text
);
2024-11-10 00:18:52 +00:00
ALTER TABLE musicrelease ADD CONSTRAINT musicrelease_pk PRIMARY KEY (id);
--
-- Music links (external platform links under a release)
--
2024-11-10 00:18:52 +00:00
CREATE TABLE musiclink (
release character varying(64) NOT NULL,
name text NOT NULL,
url text NOT NULL
);
2024-11-10 00:18:52 +00:00
ALTER TABLE musiclink ADD CONSTRAINT musiclink_pk PRIMARY KEY (release, name);
--
-- Music credits (artist credits under a release)
--
2024-11-10 00:18:52 +00:00
CREATE TABLE musiccredit (
release character varying(64) NOT NULL,
artist character varying(64) NOT NULL,
role text NOT NULL,
is_primary boolean DEFAULT false
);
2024-11-10 00:18:52 +00:00
ALTER TABLE musiccredit ADD CONSTRAINT musiccredit_pk PRIMARY KEY (release, artist);
--
-- Music tracks (tracks under a release)
--
2024-11-10 00:18:52 +00:00
CREATE TABLE musictrack (
id uuid DEFAULT gen_random_uuid(),
title text NOT NULL,
description text,
lyrics text,
preview_url text
);
2024-11-10 00:18:52 +00:00
ALTER TABLE musictrack ADD CONSTRAINT musictrack_pk PRIMARY KEY (id);
--
-- Music release/track pairs
--
2024-11-10 00:18:52 +00:00
CREATE TABLE musicreleasetrack (
release character varying(64) NOT NULL,
track uuid NOT NULL,
number integer NOT NULL
);
2024-11-10 00:18:52 +00:00
ALTER TABLE musicreleasetrack ADD CONSTRAINT musicreleasetrack_pk PRIMARY KEY (release, track);
--
-- Foreign keys
--
2024-11-10 00:18:52 +00:00
ALTER TABLE musiccredit ADD CONSTRAINT musiccredit_artist_fk FOREIGN KEY (artist) REFERENCES artist(id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE musiccredit ADD CONSTRAINT musiccredit_release_fk FOREIGN KEY (release) REFERENCES musicrelease(id) ON DELETE CASCADE;
ALTER TABLE musiclink ADD CONSTRAINT musiclink_release_fk FOREIGN KEY (release) REFERENCES musicrelease(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE musicreleasetrack ADD CONSTRAINT music_pair_trackref_fk FOREIGN KEY (release) REFERENCES musicrelease(id) ON DELETE CASCADE;
ALTER TABLE musicreleasetrack ADD CONSTRAINT music_pair_releaseref_fk FOREIGN KEY (track) REFERENCES musictrack(id) ON DELETE CASCADE;