new-life-songs/service/src/main/sql/20170209113022-create-schema-up.sql
Jonathan Bernard 7d7f2eed87 Re-organized into two submodules: service and uploader.
Moved all the existing service code into the `service` submodule.

Stubbed out project and GUI frame for the uploader. Idea is to have a GUI that
infers all the correct meta-data from media tag values and creates service,
songs, and performance records appropriately based on the tagged mp3/ogg files
of the performances.
2017-02-11 23:53:04 -06:00

54 lines
1.5 KiB
SQL

-- # New Life Songs DB
-- @author Jonathan Bernard <jdb@jdb-labs.com>
--
-- PostgreSQL database creation sript.
-- Services table
CREATE TABLE services (
id SERIAL,
date DATE NOT NULL,
service_type VARCHAR(16) DEFAULT NULL,
description VARCHAR(255) DEFAULT NULL,
CONSTRAINT uc_serviceTypeAndDate UNIQUE (date, service_type),
PRIMARY KEY (id));
-- Songs table
CREATE TABLE songs (
id SERIAL,
name VARCHAR(128) NOT NULL,
artists VARCHAR(256) DEFAULT NULL,
CONSTRAINT uc_songNameAndArtist UNIQUE (name, artists),
PRIMARY KEY (id));
-- performances table
CREATE TABLE performances (
service_id INTEGER NOT NULL,
song_id INTEGER NOT NULL,
pianist VARCHAR(64) DEFAULT NULL,
organist VARCHAR(64) DEFAULT NULL,
bassist VARCHAR(64) DEFAULT NULL,
drummer VARCHAR(64) DEFAULT NULL,
guitarist VARCHAR(64) DEFAULT NULL,
leader VARCHAR(64) DEFAULT NULL,
PRIMARY KEY (service_id, song_id),
FOREIGN KEY (service_id) REFERENCES services (id) ON DELETE CASCADE,
FOREIGN KEY (song_id) REFERENCES songs (id) ON DELETE CASCADE);
-- Users table
CREATE TABLE users (
id SERIAL,
username VARCHAR(64) UNIQUE NOT NULL,
pwd VARCHAR(80),
role VARCHAR(16) NOT NULL,
PRIMARY KEY (id));
-- Tokens table
CREATE TABLE tokens (
token VARCHAR(64),
user_id INTEGER NOT NULL,
expires TIMESTAMP NOT NULL,
PRIMARY KEY (token),
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE);