2014-06-12 13:45:10 +00:00
|
|
|
CREATE TABLE folder (
|
2018-03-17 22:25:26 +00:00
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
root BOOLEAN NOT NULL,
|
|
|
|
name CITEXT NOT NULL,
|
|
|
|
path VARCHAR(4096) NOT NULL,
|
|
|
|
path_hash BYTEA NOT NULL,
|
|
|
|
created TIMESTAMP NOT NULL,
|
2018-05-21 14:16:06 +00:00
|
|
|
cover_art VARCHAR(256),
|
2018-03-17 22:25:26 +00:00
|
|
|
last_scan INTEGER NOT NULL,
|
|
|
|
parent_id UUID REFERENCES folder
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
2018-03-17 22:25:26 +00:00
|
|
|
CREATE UNIQUE INDEX index_folder_path ON folder(path_hash);
|
|
|
|
|
2014-06-12 13:45:10 +00:00
|
|
|
CREATE TABLE artist (
|
2018-03-17 22:25:26 +00:00
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
name CITEXT NOT NULL
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE album (
|
2018-03-17 22:25:26 +00:00
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
name CITEXT NOT NULL,
|
|
|
|
artist_id UUID NOT NULL REFERENCES artist
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE track (
|
2018-03-17 22:25:26 +00:00
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
disc INTEGER NOT NULL,
|
|
|
|
number INTEGER NOT NULL,
|
|
|
|
title CITEXT NOT NULL,
|
|
|
|
year INTEGER,
|
|
|
|
genre VARCHAR(256),
|
|
|
|
duration INTEGER NOT NULL,
|
|
|
|
album_id UUID NOT NULL REFERENCES album,
|
|
|
|
artist_id UUID NOT NULL REFERENCES artist,
|
|
|
|
bitrate INTEGER NOT NULL,
|
|
|
|
path VARCHAR(4096) NOT NULL,
|
|
|
|
path_hash BYTEA NOT NULL,
|
|
|
|
content_type VARCHAR(32) NOT NULL,
|
|
|
|
created TIMESTAMP NOT NULL,
|
|
|
|
last_modification INTEGER NOT NULL,
|
|
|
|
play_count INTEGER NOT NULL,
|
|
|
|
last_play TIMESTAMP,
|
|
|
|
root_folder_id UUID NOT NULL REFERENCES folder,
|
|
|
|
folder_id UUID NOT NULL REFERENCES folder
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
2018-03-17 22:25:26 +00:00
|
|
|
CREATE UNIQUE INDEX index_track_path ON track(path_hash);
|
|
|
|
|
2014-06-12 13:45:10 +00:00
|
|
|
CREATE TABLE "user" (
|
2018-03-17 22:25:26 +00:00
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
name VARCHAR(64) NOT NULL,
|
|
|
|
mail VARCHAR(256),
|
|
|
|
password CHAR(40) NOT NULL,
|
|
|
|
salt CHAR(6) NOT NULL,
|
|
|
|
admin BOOLEAN NOT NULL,
|
|
|
|
lastfm_session CHAR(32),
|
|
|
|
lastfm_status BOOLEAN NOT NULL,
|
|
|
|
last_play_id UUID REFERENCES track,
|
|
|
|
last_play_date TIMESTAMP
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE client_prefs (
|
2018-03-17 22:25:26 +00:00
|
|
|
user_id UUID NOT NULL,
|
|
|
|
client_name VARCHAR(32) NOT NULL,
|
|
|
|
format VARCHAR(8),
|
|
|
|
bitrate INTEGER,
|
|
|
|
PRIMARY KEY (user_id, client_name)
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE starred_folder (
|
2018-03-17 22:25:26 +00:00
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
starred_id UUID NOT NULL REFERENCES folder,
|
|
|
|
date TIMESTAMP NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, starred_id)
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE starred_artist (
|
2018-03-17 22:25:26 +00:00
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
starred_id UUID NOT NULL REFERENCES artist,
|
|
|
|
date TIMESTAMP NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, starred_id)
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE starred_album (
|
2018-03-17 22:25:26 +00:00
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
starred_id UUID NOT NULL REFERENCES album,
|
|
|
|
date TIMESTAMP NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, starred_id)
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE starred_track (
|
2018-03-17 22:25:26 +00:00
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
starred_id UUID NOT NULL REFERENCES track,
|
|
|
|
date TIMESTAMP NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, starred_id)
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE rating_folder (
|
2018-03-17 22:25:26 +00:00
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
rated_id UUID NOT NULL REFERENCES folder,
|
|
|
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
|
|
|
PRIMARY KEY (user_id, rated_id)
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE rating_track (
|
2018-03-17 22:25:26 +00:00
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
rated_id UUID NOT NULL REFERENCES track,
|
|
|
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
|
|
|
PRIMARY KEY (user_id, rated_id)
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE chat_message (
|
2018-03-17 22:25:26 +00:00
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
time INTEGER NOT NULL,
|
|
|
|
message VARCHAR(512) NOT NULL
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE playlist (
|
2018-03-17 22:25:26 +00:00
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
user_id UUID NOT NULL REFERENCES "user",
|
|
|
|
name VARCHAR(256) NOT NULL,
|
|
|
|
comment VARCHAR(256),
|
|
|
|
public BOOLEAN NOT NULL,
|
|
|
|
created TIMESTAMP NOT NULL,
|
|
|
|
tracks TEXT
|
2014-06-12 13:45:10 +00:00
|
|
|
);
|
|
|
|
|