]> git.sesse.net Git - ccbs/blobdiff - sql/ccbs.sql
Add error template.
[ccbs] / sql / ccbs.sql
index 0bbc0097b8f0212b58017c3bfd6adf42a7e4fdd4..e8045a0046ee21b8f52219c73f2bac3f061c8898 100644 (file)
@@ -53,7 +53,7 @@ CREATE TABLE seasons (
        season SERIAL PRIMARY KEY,
        name VARCHAR NOT NULL,
 
        season SERIAL PRIMARY KEY,
        name VARCHAR NOT NULL,
 
-       UNIQUE ( season )
+       UNIQUE ( name )
 );
 
 CREATE TABLE tournaments (
 );
 
 CREATE TABLE tournaments (
@@ -64,7 +64,9 @@ CREATE TABLE tournaments (
        location VARCHAR NOT NULL,
        "date" DATE NOT NULL,
        machine INTEGER NOT NULL REFERENCES machines,
        location VARCHAR NOT NULL,
        "date" DATE NOT NULL,
        machine INTEGER NOT NULL REFERENCES machines,
-       scoringsystem INTEGER NOT NULL REFERENCES scoringsystems
+       scoringsystem INTEGER NOT NULL REFERENCES scoringsystems,
+
+       UNIQUE ( season, name )
 );
 
 CREATE TABLE rounds (
 );
 
 CREATE TABLE rounds (
@@ -100,8 +102,10 @@ CREATE TABLE roundparticipation (
        round INTEGER NOT NULL,
        parallel INTEGER NOT NULL,
        player INTEGER NOT NULL REFERENCES players,
        round INTEGER NOT NULL,
        parallel INTEGER NOT NULL,
        player INTEGER NOT NULL REFERENCES players,
+       position INTEGER NOT NULL,
 
        UNIQUE (tournament, round, player),
 
        UNIQUE (tournament, round, player),
+       UNIQUE (tournament, round, parallel, position),
        FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
        PRIMARY KEY (tournament, round, parallel, player)
 );
        FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
        PRIMARY KEY (tournament, round, parallel, player)
 );
@@ -111,6 +115,7 @@ CREATE TABLE scores (
        round INTEGER NOT NULL,
        parallel INTEGER NOT NULL,
        player INTEGER NOT NULL REFERENCES players,
        round INTEGER NOT NULL,
        parallel INTEGER NOT NULL,
        player INTEGER NOT NULL REFERENCES players,
+       songnumber INTEGER NOT NULL,
        
        song INTEGER NOT NULL REFERENCES songs,
        playmode VARCHAR CHECK (playmode IS NULL OR playmode IN ('single','double')),
        
        song INTEGER NOT NULL REFERENCES songs,
        playmode VARCHAR CHECK (playmode IS NULL OR playmode IN ('single','double')),
@@ -122,5 +127,6 @@ CREATE TABLE scores (
        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),
        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),
+       UNIQUE (tournament, round, parallel, player, songnumber),
        PRIMARY KEY (tournament, round, parallel, player, song)
 );
        PRIMARY KEY (tournament, round, parallel, player, song)
 );