]> git.sesse.net Git - ccbs/blobdiff - sql/ccbs.sql
Change all instances of "name" to something more sane, to get easy natural joins.
[ccbs] / sql / ccbs.sql
index b8660671f1a89548a8788da21a267f0bb8599f2e..e0b62840e2a78a63994a78038fc91d0b9aec9812 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,22 @@ 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 rounds (
 );
 
 CREATE TABLE rounds (
@@ -102,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)
 );
@@ -113,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')),
@@ -124,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)
 );