3 CREATE TABLE machines (
4 machine SERIAL PRIMARY KEY,
5 machinename VARCHAR NOT NULL,
10 CREATE TABLE countries (
11 country SERIAL PRIMARY KEY,
12 countryname VARCHAR NOT NULL,
14 UNIQUE ( countryname )
18 song SERIAL PRIMARY KEY,
19 title VARCHAR NOT NULL,
20 artist VARCHAR NOT NULL,
21 minbpm INTEGER NOT NULL,
22 maxbpm INTEGER NOT NULL,
27 CREATE TABLE machinesongs (
28 song INTEGER NOT NULL REFERENCES songs,
29 machine INTEGER NOT NULL REFERENCES machines,
31 PRIMARY KEY ( song, machine )
34 CREATE TABLE scoringsystems (
35 scoringsystem SERIAL PRIMARY KEY,
36 scoringsystemname VARCHAR NOT NULL,
38 UNIQUE ( scoringsystemname )
41 CREATE TABLE songratings (
42 song INTEGER NOT NULL REFERENCES songs, -- strictly song+machine
43 playmode VARCHAR NOT NULL CHECK (playmode IN ('single','double')),
44 difficulty VARCHAR NOT NULL CHECK (difficulty IN ('beginner','standard','difficult','expert','challenge')),
45 feetrating INTEGER NOT NULL CHECK (feetrating >= 0 AND feetrating <= 10),
47 PRIMARY KEY (song, playmode, difficulty)
50 CREATE TABLE players (
51 player SERIAL PRIMARY KEY,
52 nick VARCHAR NOT NULL,
57 CREATE TABLE seasons (
58 season SERIAL PRIMARY KEY,
59 seasonname VARCHAR NOT NULL,
64 CREATE TABLE tournaments (
65 tournament SERIAL PRIMARY KEY,
66 season INTEGER NOT NULL REFERENCES seasons,
67 tournamentname VARCHAR NOT NULL,
68 country INTEGER NOT NULL REFERENCES countries,
69 location VARCHAR NOT NULL,
71 machine INTEGER NOT NULL REFERENCES machines,
72 scoringsystem INTEGER NOT NULL REFERENCES scoringsystems,
74 UNIQUE ( season, tournamentname )
77 CREATE TABLE tournamentparticipation (
78 tournament INTEGER NOT NULL REFERENCES tournaments,
79 player INTEGER NOT NULL REFERENCES players,
80 paid BOOLEAN NOT NULL,
82 PRIMARY KEY ( tournament, player )
85 CREATE TABLE tournamentrankings (
86 tournament INTEGER NOT NULL REFERENCES tournaments,
87 ranking INTEGER NOT NULL,
88 player INTEGER NOT NULL REFERENCES players,
91 UNIQUE (tournament, player),
92 PRIMARY KEY (tournament, ranking)
96 tournament INTEGER NOT NULL REFERENCES tournaments,
97 round INTEGER NOT NULL,
98 randomsongs INTEGER NOT NULL,
99 chosensongs INTEGER NOT NULL,
100 numqualifying INTEGER,
102 PRIMARY KEY (tournament, round)
105 CREATE TABLE groups (
106 tournament INTEGER NOT NULL REFERENCES tournaments,
107 round INTEGER NOT NULL,
108 parallel INTEGER NOT NULL,
110 FOREIGN KEY (tournament, round) REFERENCES rounds (tournament, round),
111 PRIMARY KEY (tournament, round, parallel)
114 CREATE TABLE roundrandomsongs (
115 tournament INTEGER NOT NULL,
116 round INTEGER NOT NULL,
117 parallel INTEGER NOT NULL,
118 song INTEGER NOT NULL REFERENCES songs,
120 FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
121 PRIMARY KEY (tournament, round, parallel, song)
124 CREATE TABLE roundparticipation (
125 tournament INTEGER NOT NULL,
126 round INTEGER NOT NULL,
127 parallel INTEGER NOT NULL,
128 player INTEGER NOT NULL REFERENCES players,
129 position INTEGER NOT NULL,
131 UNIQUE (tournament, round, player),
132 UNIQUE (tournament, round, parallel, position),
133 FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
134 PRIMARY KEY (tournament, round, parallel, player)
137 CREATE TABLE scores (
138 tournament INTEGER NOT NULL,
139 round INTEGER NOT NULL,
140 parallel INTEGER NOT NULL,
141 player INTEGER NOT NULL REFERENCES players,
142 songnumber INTEGER NOT NULL,
144 song INTEGER REFERENCES songs,
145 playmode VARCHAR CHECK (playmode IS NULL OR playmode IN ('single','double')),
146 difficulty VARCHAR CHECK (difficulty IS NULL OR difficulty IN ('beginner','standard','difficult','expert','challenge')),
149 score INTEGER CHECK (score IS NULL OR (score >= 0 AND score <= 10000)),
151 FOREIGN KEY (song, playmode, difficulty) REFERENCES songratings (song, playmode, difficulty),
152 FOREIGN KEY (tournament, round, parallel, player) REFERENCES roundparticipation (tournament, round, parallel, player),
153 PRIMARY KEY (tournament, round, parallel, player, songnumber)
156 CREATE TABLE randomsongsused (
157 song INTEGER NOT NULL PRIMARY KEY REFERENCES songs