mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add server
This commit is contained in:
parent
775f3ffe90
commit
d0c25531d3
27 changed files with 1725 additions and 3 deletions
|
|
@ -0,0 +1,6 @@
|
|||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
|
||||
DROP FUNCTION IF EXISTS diesel_set_updated_at();
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
|
||||
|
||||
|
||||
-- Sets up a trigger for the given table to automatically set a column called
|
||||
-- `updated_at` whenever the row is modified (unless `updated_at` was included
|
||||
-- in the modified columns)
|
||||
--
|
||||
-- # Example
|
||||
--
|
||||
-- ```sql
|
||||
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
|
||||
--
|
||||
-- SELECT diesel_manage_updated_at('users');
|
||||
-- ```
|
||||
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
|
||||
BEGIN
|
||||
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
|
||||
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
IF (
|
||||
NEW IS DISTINCT FROM OLD AND
|
||||
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
|
||||
) THEN
|
||||
NEW.updated_at := current_timestamp;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
DROP TABLE performances;
|
||||
|
||||
DROP TABLE recordings;
|
||||
|
||||
DROP TABLE ensembles;
|
||||
|
||||
DROP TABLE work_sections;
|
||||
|
||||
DROP TABLE work_parts;
|
||||
|
||||
DROP TABLE instrumentations;
|
||||
|
||||
DROP TABLE works;
|
||||
|
||||
DROP TABLE instruments;
|
||||
|
||||
DROP TABLE persons;
|
||||
|
||||
DROP TABLE users;
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
CREATE TABLE users (
|
||||
username TEXT NOT NULL PRIMARY KEY,
|
||||
password_hash TEXT NOT NULL,
|
||||
email TEXT,
|
||||
is_admin BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
is_editor BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
is_banned BOOLEAN NOT NULL DEFAULT FALSE
|
||||
);
|
||||
|
||||
CREATE TABLE persons (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL REFERENCES users(username)
|
||||
);
|
||||
|
||||
CREATE TABLE instruments (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL REFERENCES users(username)
|
||||
);
|
||||
|
||||
CREATE TABLE works (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
composer BIGINT NOT NULL REFERENCES persons(id),
|
||||
title TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL REFERENCES users(username)
|
||||
);
|
||||
|
||||
CREATE TABLE instrumentations (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
work BIGINT NOT NULL REFERENCES works(id) ON DELETE CASCADE,
|
||||
instrument BIGINT NOT NULL REFERENCES instruments(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE work_parts (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
work BIGINT NOT NULL REFERENCES works(id) ON DELETE CASCADE,
|
||||
part_index BIGINT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
composer BIGINT REFERENCES persons(id)
|
||||
);
|
||||
|
||||
CREATE TABLE work_sections (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
work BIGINT NOT NULL REFERENCES works(id) ON DELETE CASCADE,
|
||||
title TEXT NOT NULL,
|
||||
before_index BIGINT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE ensembles (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL REFERENCES users(username)
|
||||
);
|
||||
|
||||
CREATE TABLE recordings (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
work BIGINT NOT NULL REFERENCES works(id),
|
||||
comment TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL REFERENCES users(username)
|
||||
);
|
||||
|
||||
CREATE TABLE performances (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
recording BIGINT NOT NULL REFERENCES recordings(id) ON DELETE CASCADE,
|
||||
person BIGINT REFERENCES persons(id),
|
||||
ensemble BIGINT REFERENCES ensembles(id),
|
||||
role BIGINT REFERENCES instruments(id)
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue