move queries to db folder, change database to better accommodate musicbrainz api data

This commit is contained in:
Chiel Suttorp
2026-03-26 16:31:38 +01:00
parent e69ac3a305
commit e3176871ab
6 changed files with 21 additions and 7 deletions
+20 -6
View File
@@ -8,29 +8,43 @@ CREATE TABLE IF NOT EXISTS users (
CREATE TABLE IF NOT EXISTS albums (
id UUID PRIMARY KEY,
musicbrainz_id UUID UNIQUE,
name VARCHAR(255) NOT NULL,
artist VARCHAR(255) NOT NULL,
extra_info VARCHAR(255),
artist_id VARCHAR(255) NOT NULL,
release_date DATE,
album_art_url VARCHAR(255)
FOREIGN KEY (artist_id) REFERENCES artists(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS artists (
id UUID PRIMARY KEY,
musicbrainz_id UUID UNIQUE,
name VARCHAR(255) NOT NULL,
genre VARCHAR(255),
bio TEXT,
artist_image_url VARCHAR(255)
);
CREATE TABLE IF NOT EXISTS user_albums (
user_id UUID,
user_id UUID PRIMARY KEY,
album_id UUID,
date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
album_owned BOOLEAN NOT NULL DEFAULT FALSE,
album_want BOOLEAN NOT NULL DEFAULT FALSE,
album_condition VARCHAR(50) CHECK (album_condition IN ('Mint', 'Near Mint', 'Very Good Plus', 'Very Good', 'Good Plus', 'Good', 'Fair', 'Poor')),
is_vinyl BOOLEAN NOT NULL DEFAULT FALSE,
is_cd BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (user_id, album_id),
FOREIGN KEY (user_id) REFERENCES Users(id) ON DELETE CASCADE,
FOREIGN KEY (album_id) REFERENCES Albums(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS tags (
id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS artist_tags (
artist_id UUID PRIMARY KEY,
tag_id UUID,
FOREIGN KEY (artist_id) REFERENCES Artists(id) ON DELETE CASCADE,
FOREIGN KEY (tag_id) REFERENCES Tags(id) ON DELETE CASCADE
);