2021-03-27 05:33:44 +00:00
|
|
|
START TRANSACTION;
|
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS links (
|
|
|
|
scrobble uuid NOT NULL,
|
|
|
|
track uuid NOT NULL,
|
|
|
|
PRIMARY KEY (scrobble, track)
|
|
|
|
);
|
2021-03-27 05:33:44 +00:00
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE INDEX trackLookup ON links (track);
|
2021-03-27 05:33:44 +00:00
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS artists (
|
|
|
|
uuid uuid PRIMARY KEY,
|
|
|
|
name VARCHAR(255) NOT NULL,
|
|
|
|
"desc" TEXT,
|
|
|
|
img VARCHAR(255)
|
|
|
|
);
|
2021-03-27 05:33:44 +00:00
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS albums (
|
|
|
|
uuid uuid PRIMARY KEY,
|
|
|
|
name VARCHAR(255) NOT NULL,
|
|
|
|
"desc" TEXT,
|
|
|
|
img VARCHAR(255)
|
|
|
|
);
|
2021-03-27 05:33:44 +00:00
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS tracks (
|
|
|
|
uuid uuid PRIMARY KEY,
|
|
|
|
name VARCHAR(255) NOT NULL,
|
|
|
|
"desc" TEXT,
|
|
|
|
img VARCHAR(255)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scrobbles (
|
|
|
|
uuid uuid PRIMARY KEY,
|
|
|
|
created_at timestamptz NOT NULL,
|
|
|
|
created_ip INET NULL,
|
|
|
|
"user" uuid NOT NULL,
|
|
|
|
track uuid NOT NULL,
|
|
|
|
source VARCHAR(100) NOT NULL DEFAULT '',
|
2021-03-27 05:33:44 +00:00
|
|
|
FOREIGN KEY (track) REFERENCES tracks(uuid),
|
2021-12-25 09:24:47 +00:00
|
|
|
FOREIGN KEY ("user") REFERENCES users(uuid)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE INDEX scrobblesUserLookup ON scrobbles ("user");
|
|
|
|
CREATE INDEX scrobblesDateLookup ON scrobbles (created_at);
|
|
|
|
CREATE INDEX scrobblesSourceLookup ON scrobbles (source);
|
2021-03-27 05:33:44 +00:00
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS album_artist (
|
|
|
|
album uuid NOT NULL,
|
|
|
|
artist uuid NOT NULL,
|
|
|
|
PRIMARY KEY (album, artist),
|
2021-03-28 08:52:34 +00:00
|
|
|
FOREIGN KEY (album) REFERENCES albums(uuid),
|
2021-03-27 05:33:44 +00:00
|
|
|
FOREIGN KEY (artist) REFERENCES artists(uuid)
|
2021-12-25 09:24:47 +00:00
|
|
|
);
|
2021-03-27 05:33:44 +00:00
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS track_album (
|
|
|
|
track uuid NOT NULL,
|
|
|
|
album uuid NOT NULL,
|
|
|
|
PRIMARY KEY (track, album),
|
2021-03-28 08:52:34 +00:00
|
|
|
FOREIGN KEY (track) REFERENCES tracks(uuid),
|
|
|
|
FOREIGN KEY (album) REFERENCES albums(uuid)
|
2021-12-25 09:24:47 +00:00
|
|
|
);
|
2021-03-28 08:52:34 +00:00
|
|
|
|
2021-12-25 09:24:47 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS track_artist (
|
|
|
|
track uuid NOT NULL,
|
|
|
|
artist uuid NOT NULL,
|
|
|
|
PRIMARY KEY (track, artist),
|
2021-03-28 08:52:34 +00:00
|
|
|
FOREIGN KEY (track) REFERENCES tracks(uuid),
|
2021-03-27 05:33:44 +00:00
|
|
|
FOREIGN KEY (artist) REFERENCES artists(uuid)
|
2021-12-25 09:24:47 +00:00
|
|
|
);
|
2021-03-27 05:33:44 +00:00
|
|
|
|
|
|
|
COMMIT;
|