enhanced data model and sql builder.sh script to manage complex alter table scenario...
[brisk.git] / sql / sql.d / 060-tournament.sql
1 DROP TABLE #PFX#bin5_tournaments;
2 CREATE TABLE #PFX#bin5_tournaments (
3        code   SERIAL PRIMARY KEY,
4        name   text
5        );
6
7 -- add tournaments and field in the bin5_matches table
8 INSERT INTO #PFX#bin5_tournaments (code, name) VALUES (1, 'normal match');
9 ALTER SEQUENCE #PFX#bin5_tournaments_code_seq RESTART WITH 2;
10
11 ALTER TABLE #PFX#bin5_matches DROP COLUMN tourn;
12 ALTER TABLE #PFX#bin5_matches ADD COLUMN tourn integer DEFAULT 1;
13
14 ALTER TABLE #PFX#bin5_matches DROP CONSTRAINT #PFX#bin5_matches_tourn_fkey;
15 ALTER TABLE #PFX#bin5_matches ADD FOREIGN KEY (tourn) REFERENCES #PFX#bin5_tournaments(code) ON UPDATE cascade ON DELETE cascade;
16