+-- vim:set tw=0:
+
+CREATE TABLE machines (
+ machine SERIAL PRIMARY KEY,
+ name VARCHAR NOT NULL
+);
+
+CREATE TABLE countries (
+ country SERIAL PRIMARY KEY,
+ name VARCHAR NOT NULL
+);
CREATE TABLE songs (
song SERIAL PRIMARY KEY,
artist VARCHAR NOT NULL
);
+-- CREATE TABLE machinesongs etc.
+
+CREATE TABLE scoringsystems (
+ scoringsystem SERIAL PRIMARY KEY,
+ name VARCHAR NOT NULL
+);
+
CREATE TABLE songratings (
- song INTEGER NOT NULL REFERENCES songs,
- playmode VARCHAR NOT NULL CHECK playmode IN ('single','double'),
- difficulty VARCHAR NOT NULL CHECK difficulty IN ('beginner','standard','difficult','expert','challenge'),
- feetrating INTEGER NOT NULL CHECK (feetrating >= 0 AND feetrating <= 10)
+ song INTEGER NOT NULL REFERENCES songs, -- strictly song+machine
+ playmode VARCHAR NOT NULL CHECK (playmode IN ('single','double')),
+ difficulty VARCHAR NOT NULL CHECK (difficulty IN ('beginner','standard','difficult','expert','challenge')),
+ feetrating INTEGER NOT NULL CHECK (feetrating >= 0 AND feetrating <= 10),
PRIMARY KEY (song, playmode, difficulty)
);
name VARCHAR NOT NULL
);
-CREATE TABLE tournament (
+CREATE TABLE tournaments (
tournament SERIAL PRIMARY KEY,
season INTEGER NOT NULL REFERENCES seasons,
- name VARCHAR NOT NULL
+ name VARCHAR NOT NULL,
+ country INTEGER NOT NULL REFERENCES countries,
+ location VARCHAR NOT NULL,
+ "date" DATE NOT NULL,
+ machine INTEGER NOT NULL REFERENCES machines,
+ scoringsystem INTEGER NOT NULL REFERENCES scoringsystems
);
CREATE TABLE rounds (
tournament INTEGER NOT NULL REFERENCES tournaments,
- level INTEGER NOT NULL,
- parallel INTEGER NOT NULL
+ round INTEGER NOT NULL,
+ randomsongs INTEGER NOT NULL,
+ chosensongs INTEGER NOT NULL,
- PRIMARY KEY (tournament, level, parallel)
+ PRIMARY KEY (tournament, round)
+);
+
+CREATE TABLE groups (
+ tournament INTEGER NOT NULL REFERENCES tournaments,
+ round INTEGER NOT NULL,
+ parallel INTEGER NOT NULL,
+
+ FOREIGN KEY (tournament, round) REFERENCES rounds (tournament, round),
+ PRIMARY KEY (tournament, round, parallel)
+);
+
+CREATE TABLE roundrandomsongs (
+ tournament INTEGER NOT NULL,
+ round INTEGER NOT NULL,
+ parallel INTEGER NOT NULL,
+ song INTEGER NOT NULL REFERENCES songs,
+
+ FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
+ PRIMARY KEY (tournament, round, parallel, song)
);
CREATE TABLE roundparticipation (
tournament INTEGER NOT NULL,
- level INTEGER NOT NULL,
+ round INTEGER NOT NULL,
parallel INTEGER NOT NULL,
player INTEGER NOT NULL REFERENCES players,
- FOREIGN KEY ( tournament, level, parallel ) REFERENCES rounds ( tournament, level, parallel ),
- PRIMARY KEY ( tournament, level, parallel, player )
+ UNIQUE (tournament, round, player),
+ FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
+ PRIMARY KEY (tournament, round, parallel, player)
+);
+
+CREATE TABLE scores (
+ tournament INTEGER NOT NULL,
+ round INTEGER NOT NULL,
+ parallel INTEGER NOT NULL,
+ player INTEGER NOT NULL REFERENCES players,
+
+ song INTEGER NOT NULL REFERENCES songs,
+ playmode VARCHAR CHECK (playmode IS NULL OR playmode IN ('single','double')),
+ difficulty VARCHAR CHECK (difficulty IS NULL OR difficulty IN ('beginner','standard','difficult','expert','challenge')),
+
+ chosen BOOLEAN NOT NULL,
+ score INTEGER NOT NULL CHECK (score >= 0 AND score <= 10000),
+
+ FOREIGN KEY (song) REFERENCES songs (song),
+ FOREIGN KEY (song, playmode, difficulty) REFERENCES songratings (song, playmode, difficulty),
+ FOREIGN KEY (tournament, round, parallel, player) REFERENCES roundparticipation (tournament, round, parallel, player),
+ PRIMARY KEY (tournament, round, parallel, player, song)
);