]> git.sesse.net Git - ccbs/blobdiff - sql/ccbs.sql
Add a template and functions for signalling user errors (as opposed to internal errors).
[ccbs] / sql / ccbs.sql
index e452d387d0134da2b1c0d8908f4c012530af4ad4..b7d342a91551b4bcd9d5185031b39c7906327352 100644 (file)
@@ -2,16 +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 ( name )
+       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 ( name )
+       UNIQUE ( countryname )
 );
 
 CREATE TABLE songs (
 );
 
 CREATE TABLE songs (
@@ -28,9 +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 ( name )
+       UNIQUE ( scoringsystemname )
 );
 
 CREATE TABLE songratings (
 );
 
 CREATE TABLE songratings (
@@ -51,22 +51,32 @@ CREATE TABLE players (
 
 CREATE TABLE seasons (
        season SERIAL PRIMARY KEY,
 
 CREATE TABLE seasons (
        season SERIAL PRIMARY KEY,
-       name VARCHAR NOT NULL,
+       seasonname VARCHAR NOT NULL,
 
 
-       UNIQUE ( season )
+       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,
        scoringsystem INTEGER NOT NULL REFERENCES scoringsystems,
 
        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,
 
-       UNIQUE ( season, name )
+       UNIQUE ( season, tournamentname )
+);
+
+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 (
@@ -115,6 +125,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')),
@@ -126,5 +137,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)
 );