more robust sql scripts adding IF EXISTS to DROP TABLE statementes
[brisk.git] / sql / sql.d / 050-bin5.sql
1 --
2 -- briskin5 (bin5) related tables
3 --
4
5 DROP TABLE IF EXISTS #PFX#bin5_matches;
6 CREATE TABLE #PFX#bin5_matches (
7        code   SERIAL PRIMARY KEY,
8        ttok   text UNIQUE,              -- token associated to the match
9        tidx   integer                   -- table index
10        );
11
12 DROP TABLE IF EXISTS #PFX#bin5_games;
13 CREATE TABLE #PFX#bin5_games (
14        code   SERIAL PRIMARY KEY,
15        mcode  integer REFERENCES #PFX#bin5_matches (code) ON DELETE cascade ON UPDATE cascade,
16        tstamp timestamp                 -- end game time
17        );
18        
19 DROP TABLE IF EXISTS #PFX#bin5_points;
20 CREATE TABLE #PFX#bin5_points (
21        gcode  integer REFERENCES #PFX#bin5_games (code) ON DELETE cascade ON UPDATE cascade,
22        ucode  integer REFERENCES #PFX#users (code) ON DELETE cascade ON UPDATE cascade, 
23        pts    integer                   -- points                 
24        );
25