X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=sql%2Fccbs.sql;h=e8045a0046ee21b8f52219c73f2bac3f061c8898;hp=e4a129f4ee631c60762afd4c727837d39c85b807;hb=95cf63732aee7601870ff706a20ac3f3f77c7114;hpb=350d05f86323a38200ed507c2541bf52f6617252 diff --git a/sql/ccbs.sql b/sql/ccbs.sql index e4a129f..e8045a0 100644 --- a/sql/ccbs.sql +++ b/sql/ccbs.sql @@ -2,12 +2,16 @@ CREATE TABLE machines ( machine SERIAL PRIMARY KEY, - name VARCHAR NOT NULL + name VARCHAR NOT NULL, + + UNIQUE ( name ) ); CREATE TABLE countries ( country SERIAL PRIMARY KEY, - name VARCHAR NOT NULL + name VARCHAR NOT NULL, + + UNIQUE ( name ) ); CREATE TABLE songs ( @@ -24,7 +28,9 @@ CREATE TABLE songs ( CREATE TABLE scoringsystems ( scoringsystem SERIAL PRIMARY KEY, - name VARCHAR NOT NULL + name VARCHAR NOT NULL, + + UNIQUE ( name ) ); CREATE TABLE songratings ( @@ -38,12 +44,16 @@ CREATE TABLE songratings ( CREATE TABLE players ( player SERIAL PRIMARY KEY, - nick VARCHAR NOT NULL + nick VARCHAR NOT NULL, + + UNIQUE ( nick ) ); CREATE TABLE seasons ( season SERIAL PRIMARY KEY, - name VARCHAR NOT NULL + name VARCHAR NOT NULL, + + UNIQUE ( name ) ); CREATE TABLE tournaments ( @@ -54,7 +64,9 @@ CREATE TABLE tournaments ( 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 ( @@ -90,8 +102,10 @@ CREATE TABLE roundparticipation ( 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, parallel, position), FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel), PRIMARY KEY (tournament, round, parallel, player) ); @@ -101,6 +115,7 @@ CREATE TABLE scores ( 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')), @@ -112,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), + UNIQUE (tournament, round, parallel, player, songnumber), PRIMARY KEY (tournament, round, parallel, player, song) );