Files
music-index/db/db.sql
T
2026-03-14 18:18:10 +01:00

38 lines
1.1 KiB
SQL

CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY,
user_name VARCHAR(255) NOT NULL,
user_mail VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
session_token VARCHAR(255),
session_expiry TIMESTAMP
);
CREATE TABLE IF NOT EXISTS albums (
id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL,
artist VARCHAR(255) NOT NULL,
release_date DATE,
album_art_url VARCHAR(255)
);
CREATE TABLE IF NOT EXISTS artists (
id UUID PRIMARY KEY,
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,
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,
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
);