+-- vim:set tw=0:
CREATE TABLE songs (
song SERIAL PRIMARY KEY,
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)
+ 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
player INTEGER NOT NULL REFERENCES players,
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'),
+ 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, playmode, difficulty) REFERENCES songs (song, playmode, difficulty),
- FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
- PRIMARY KEY (tournament, round, parallel, player, songs)
-);
+ 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)
+);