]> git.sesse.net Git - ccbs/blobdiff - sql/ccbs.sql
Added a "number of people qualifying for each round" attribute to the SQL schema.
[ccbs] / sql / ccbs.sql
index e4a129f4ee631c60762afd4c727837d39c85b807..c13c666774d872d199351fe59b01ba43fa468f3d 100644 (file)
@@ -2,12 +2,16 @@
 
 CREATE TABLE machines (
        machine SERIAL PRIMARY KEY,
 
 CREATE TABLE machines (
        machine SERIAL PRIMARY KEY,
-       name VARCHAR NOT NULL
+       machinename VARCHAR NOT NULL,
+
+       UNIQUE ( machinename )
 );
 
 CREATE TABLE countries (
        country SERIAL PRIMARY KEY,
 );
 
 CREATE TABLE countries (
        country SERIAL PRIMARY KEY,
-       name VARCHAR NOT NULL
+       countryname VARCHAR NOT NULL,
+
+       UNIQUE ( countryname )
 );
 
 CREATE TABLE songs (
 );
 
 CREATE TABLE songs (
@@ -24,7 +28,9 @@ CREATE TABLE songs (
 
 CREATE TABLE scoringsystems (
        scoringsystem SERIAL PRIMARY KEY,
 
 CREATE TABLE scoringsystems (
        scoringsystem SERIAL PRIMARY KEY,
-       name VARCHAR NOT NULL
+       scoringsystemname VARCHAR NOT NULL,
+       
+       UNIQUE ( scoringsystemname )
 );
 
 CREATE TABLE songratings (
 );
 
 CREATE TABLE songratings (
@@ -38,23 +44,47 @@ CREATE TABLE songratings (
 
 CREATE TABLE players (
        player SERIAL PRIMARY KEY,
 
 CREATE TABLE players (
        player SERIAL PRIMARY KEY,
-       nick VARCHAR NOT NULL
+       nick VARCHAR NOT NULL,
+
+       UNIQUE ( nick )
 );
 
 CREATE TABLE seasons (
        season SERIAL PRIMARY KEY,
 );
 
 CREATE TABLE seasons (
        season SERIAL PRIMARY KEY,
-       name VARCHAR NOT NULL
+       seasonname VARCHAR NOT NULL,
+
+       UNIQUE ( seasonname )
 );
 
 CREATE TABLE tournaments (
        tournament SERIAL PRIMARY KEY,
        season INTEGER NOT NULL REFERENCES seasons,
 );
 
 CREATE TABLE tournaments (
        tournament SERIAL PRIMARY KEY,
        season INTEGER NOT NULL REFERENCES seasons,
-       name VARCHAR NOT NULL,
+       tournamentname VARCHAR NOT NULL,
        country INTEGER NOT NULL REFERENCES countries,
        location VARCHAR NOT NULL,
        "date" DATE NOT NULL,
        machine INTEGER NOT NULL REFERENCES machines,
        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
+       scoringsystem INTEGER NOT NULL REFERENCES scoringsystems,
+
+       UNIQUE ( season, tournamentname )
+);
+
+CREATE TABLE tournamentparticipation (
+       tournament INTEGER NOT NULL REFERENCES tournaments,
+       player INTEGER NOT NULL REFERENCES players,
+       paid BOOLEAN NOT NULL,
+
+       PRIMARY KEY ( tournament, player )
+);
+
+CREATE TABLE tournamentrankings (
+       tournament INTEGER NOT NULL REFERENCES tournaments,
+       ranking INTEGER NOT NULL,
+       player INTEGER NOT NULL REFERENCES players,
+       points INTEGER,
+
+       UNIQUE (tournament, player),
+       PRIMARY KEY (tournament, ranking)
 );
 
 CREATE TABLE rounds (
 );
 
 CREATE TABLE rounds (
@@ -62,6 +92,7 @@ CREATE TABLE rounds (
        round INTEGER NOT NULL,
        randomsongs INTEGER NOT NULL,
        chosensongs INTEGER NOT NULL,
        round INTEGER NOT NULL,
        randomsongs INTEGER NOT NULL,
        chosensongs INTEGER NOT NULL,
+       numqualifying INTEGER,
 
        PRIMARY KEY (tournament, round)
 );
 
        PRIMARY KEY (tournament, round)
 );
@@ -90,8 +121,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)
 );
@@ -101,6 +134,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')),
@@ -112,5 +146,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)
 );