-- DONE - CASCADE ON DELETE of orders related tables
-- DONE - STATUS on orders
-DROP TABLE #PFX#users;
+DROP TABLE IF EXISTS #PFX#users;
CREATE TABLE #PFX#users (
code SERIAL PRIMARY KEY,
login text UNIQUE,
mtime timestamp DEFAULT to_timestamp(0) -- last access
);
-DROP TABLE #PFX#groups;
+DROP TABLE IF EXISTS #PFX#groups;
CREATE TABLE #PFX#groups (
code SERIAL PRIMARY KEY,
name text
-- briskin5 (bin5) related tables
--
-DROP TABLE #PFX#bin5_matches;
+DROP TABLE IF EXISTS #PFX#bin5_matches;
CREATE TABLE #PFX#bin5_matches (
code SERIAL PRIMARY KEY,
ttok text UNIQUE, -- token associated to the match
tidx integer -- table index
);
-DROP TABLE #PFX#bin5_games;
+DROP TABLE IF EXISTS #PFX#bin5_games;
CREATE TABLE #PFX#bin5_games (
code SERIAL PRIMARY KEY,
mcode integer REFERENCES #PFX#bin5_matches (code) ON DELETE cascade ON UPDATE cascade,
tstamp timestamp -- end game time
);
-DROP TABLE #PFX#bin5_points;
+DROP TABLE IF EXISTS #PFX#bin5_points;
CREATE TABLE #PFX#bin5_points (
gcode integer REFERENCES #PFX#bin5_games (code) ON DELETE cascade ON UPDATE cascade,
ucode integer REFERENCES #PFX#users (code) ON DELETE cascade ON UPDATE cascade,
-- wee = 4
--
-DROP TABLE #PFX#bin5_places_mtime;
+DROP TABLE IF EXISTS #PFX#bin5_places_mtime;
CREATE TABLE #PFX#bin5_places_mtime (
code int,
mtime timestamp
);
INSERT INTO #PFX#bin5_places_mtime (code, mtime) VALUES (0, now());
-DROP TABLE #PFX#bin5_places;
+DROP TABLE IF EXISTS #PFX#bin5_places;
CREATE TABLE #PFX#bin5_places (
type integer,
rank integer,
-DROP TABLE #PFX#bin5_table_orders;
+DROP TABLE IF EXISTS #PFX#bin5_table_orders;
CREATE TABLE #PFX#bin5_table_orders (
mcode integer REFERENCES #PFX#bin5_matches (code) ON DELETE cascade ON UPDATE cascade,
pos integer,
-DROP TABLE #PFX#bin5_tournaments;
+DROP TABLE IF EXISTS #PFX#bin5_tournaments;
CREATE TABLE #PFX#bin5_tournaments (
code SERIAL PRIMARY KEY,
active integer,
--
-- Table to manage mails sent to users
--
-DROP TABLE #PFX#mails;
+DROP TABLE IF EXISTS #PFX#mails;
CREATE TABLE #PFX#mails (
code SERIAL PRIMARY KEY,
ucode integer REFERENCES #PFX#users (code) ON DELETE cascade ON UPDATE cascade,
--
-- Table to manage mails sent to users
--
-DROP TABLE #PFX#selfreg_chk;
+DROP TABLE IF EXISTS #PFX#selfreg_chk;
CREATE TABLE #PFX#selfreg_chk (
ip integer, -- ip v4 address
atime timestamp DEFAULT to_timestamp(0) -- access time