more robust sql scripts adding IF EXISTS to DROP TABLE statementes
[brisk.git] / sql / sql.d / 060-tournament.sql
1 DROP TABLE IF EXISTS #PFX#bin5_tournaments;
2 CREATE TABLE #PFX#bin5_tournaments (
3        code   SERIAL PRIMARY KEY,
4        active integer,
5        name   text
6        );
7
8 -- add tournaments and field in the bin5_matches table
9 INSERT INTO #PFX#bin5_tournaments (code, active, name) VALUES (1, 1, 'normal match');
10 INSERT INTO #PFX#bin5_tournaments (code, active, name) VALUES (2, 1, 'special match');
11 ALTER SEQUENCE #PFX#bin5_tournaments_code_seq RESTART WITH 3;
12
13 ALTER TABLE #PFX#bin5_matches DROP COLUMN tcode;
14 ALTER TABLE #PFX#bin5_matches ADD COLUMN tcode integer DEFAULT 1;
15
16 ALTER TABLE #PFX#bin5_matches DROP CONSTRAINT #PFX#bin5_matches_tcode_fkey;
17 ALTER TABLE #PFX#bin5_matches ADD FOREIGN KEY (tcode) REFERENCES #PFX#bin5_tournaments(code) ON UPDATE cascade ON DELETE cascade;
18
19 ALTER TABLE #PFX#bin5_games DROP COLUMN act;
20 ALTER TABLE #PFX#bin5_games ADD COLUMN act integer DEFAULT -1;  -- end reason of the game