complete
This commit is contained in:
parent
fdb45f953e
commit
ca45a6df02
6 changed files with 58 additions and 35 deletions
|
@ -1,15 +1,16 @@
|
|||
CREATE TYPE user_role AS ENUM ('regular', 'admin');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user (
|
||||
username varchar(255) NOT NULL PRIMARY KEY,
|
||||
password text NOT NULL,
|
||||
user_role text NOT NULL DEFAULT 'Regular' CHECK (user_role IN ('regular', 'admin'))
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
username VARCHAR(255) NOT NULL PRIMARY KEY,
|
||||
"password" text NOT NULL,
|
||||
user_role user_role NOT NULL DEFAULT 'regular'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_session (
|
||||
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
token text NOT NULL,
|
||||
user varchar(255) NOT NULL,
|
||||
FOREIGN KEY(user) REFERENCES user(username)
|
||||
"user" varchar(255) NOT NULL,
|
||||
FOREIGN KEY("user") REFERENCES users(username)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS artist (
|
||||
|
@ -20,7 +21,7 @@ CREATE TABLE IF NOT EXISTS artist (
|
|||
CREATE TABLE IF NOT EXISTS album (
|
||||
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
title text NOT NULL,
|
||||
artist UUID
|
||||
artist UUID,
|
||||
FOREIGN KEY(artist) REFERENCES artist(id)
|
||||
);
|
||||
|
||||
|
@ -28,7 +29,7 @@ CREATE TABLE IF NOT EXISTS track (
|
|||
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
path text NOT NULL,
|
||||
title text,
|
||||
date_added timestampz NOT NULL DEFAULT current_timestamp,
|
||||
date_added timestamptz NOT NULL DEFAULT current_timestamp,
|
||||
album UUID,
|
||||
artist UUID,
|
||||
meta jsonb,
|
||||
|
@ -36,23 +37,27 @@ CREATE TABLE IF NOT EXISTS track (
|
|||
FOREIGN KEY(artist) REFERENCES artist(id)
|
||||
);
|
||||
|
||||
CREATE TYPE event_kind AS ENUM ('play', 'played', 'stop');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
time timestampz NOT NULL DEFAULT current_timestamp,
|
||||
kind text CHECK (kind IN ('play', 'played', 'stop')),
|
||||
user VARCHAR(255) NOT NULL,
|
||||
id UUID NOT NULL DEFAULT gen_random_uuid(),
|
||||
time timestamptz NOT NULL DEFAULT current_timestamp,
|
||||
kind event_kind NOT NULL,
|
||||
"user" VARCHAR(255) NOT NULL,
|
||||
track UUID NOT NULL,
|
||||
FOREIGN KEY(user) REFERENCES user(username),
|
||||
FOREIGN KEY("user") REFERENCES users(username),
|
||||
FOREIGN KEY(track) REFERENCES track(id)
|
||||
);
|
||||
|
||||
SELECT create_hypertable('events', by_range('time'));
|
||||
|
||||
CREATE TYPE visibility AS ENUM ('public', 'private');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS playlist (
|
||||
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
owner VARCHAR(255) NOT NULL,
|
||||
title text NOT NULL,
|
||||
visibility text NOT NULL DEFAULT 'private' CHECK (visibility IN ('public', 'private')),
|
||||
tracks UUID[] NOT NULL DEFAULT [],
|
||||
FOREIGN KEY(owner) REFERENCES user(username)
|
||||
visibility visibility NOT NULL DEFAULT 'private',
|
||||
tracks UUID[] NOT NULL DEFAULT '{}',
|
||||
FOREIGN KEY(owner) REFERENCES users(username)
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue