From: Matteo Nastasi (mop) Date: Thu, 15 Oct 2015 06:28:21 +0000 (+0200) Subject: more robust sql scripts adding IF EXISTS to DROP TABLE statementes X-Git-Tag: v5.0.0~18 X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=484a365c1e66ba4b878117275423a1594c209960;p=brisk.git more robust sql scripts adding IF EXISTS to DROP TABLE statementes --- diff --git a/sql/sql.d/001-struct.sql b/sql/sql.d/001-struct.sql index 302804e..fa1dc86 100644 --- a/sql/sql.d/001-struct.sql +++ b/sql/sql.d/001-struct.sql @@ -2,7 +2,7 @@ -- 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, @@ -13,7 +13,7 @@ CREATE TABLE #PFX#users ( 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 diff --git a/sql/sql.d/050-bin5.sql b/sql/sql.d/050-bin5.sql index 938d5d3..2f58a72 100644 --- a/sql/sql.d/050-bin5.sql +++ b/sql/sql.d/050-bin5.sql @@ -2,21 +2,21 @@ -- 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, diff --git a/sql/sql.d/051-bin5-places.sql b/sql/sql.d/051-bin5-places.sql index ebf3add..6f8d7ad 100644 --- a/sql/sql.d/051-bin5-places.sql +++ b/sql/sql.d/051-bin5-places.sql @@ -6,14 +6,14 @@ -- 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, diff --git a/sql/sql.d/054-continue-match.sql b/sql/sql.d/054-continue-match.sql index 0ed40fb..e95059a 100644 --- a/sql/sql.d/054-continue-match.sql +++ b/sql/sql.d/054-continue-match.sql @@ -1,4 +1,4 @@ -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, diff --git a/sql/sql.d/060-tournament.sql b/sql/sql.d/060-tournament.sql index 7f9e340..90b54a2 100644 --- a/sql/sql.d/060-tournament.sql +++ b/sql/sql.d/060-tournament.sql @@ -1,4 +1,4 @@ -DROP TABLE #PFX#bin5_tournaments; +DROP TABLE IF EXISTS #PFX#bin5_tournaments; CREATE TABLE #PFX#bin5_tournaments ( code SERIAL PRIMARY KEY, active integer, diff --git a/sql/sql.d/070-add-mailmgmt.sql b/sql/sql.d/070-add-mailmgmt.sql index cef0248..bfd0a24 100644 --- a/sql/sql.d/070-add-mailmgmt.sql +++ b/sql/sql.d/070-add-mailmgmt.sql @@ -1,7 +1,7 @@ -- -- 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, diff --git a/sql/sql.d/071-apprentice.sql b/sql/sql.d/071-apprentice.sql index c3a0193..376427b 100644 --- a/sql/sql.d/071-apprentice.sql +++ b/sql/sql.d/071-apprentice.sql @@ -1,7 +1,7 @@ -- -- 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