From cc9dc1ddd643ad6ff206643ffc1e94559ffd27b2 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Fri, 8 Oct 2010 17:47:49 +0200 Subject: [PATCH] Improves upgrade script. - If SOURCE_DATABASE environment variable is defined, the scripts begins by creating DATABASE and copying the content of SOURCE_DATABASE in DATABASE. This feature will be available for all future upgrade scripts that starts with "copy_db". - Disable failing (and in my point of view unfixable) statements: ALTER TABLE payment_transactions ADD UNIQUE KEY fullref (fullref) Signed-off-by: Florent Bruneau --- upgrade/1.0.1/13_payments.sql | 5 ++++- upgrade/1.0.1/update.sh | 1 + upgrade/inc/pervasive.sh | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/upgrade/1.0.1/13_payments.sql b/upgrade/1.0.1/13_payments.sql index 12ab924..6252fbd 100644 --- a/upgrade/1.0.1/13_payments.sql +++ b/upgrade/1.0.1/13_payments.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS payment_bankaccounts; CREATE TABLE payment_bankaccounts ( id integer PRIMARY KEY auto_increment, asso_id integer NOT NULL, @@ -40,6 +41,7 @@ INSERT INTO payment_bankaccounts VALUES (NULL,248,"12548029983443030151039","X-R INSERT INTO payment_bankaccounts VALUES (NULL,179,"30066106410001050600128","X-Sursaut H Levy-Lambert","used"); INSERT INTO payment_bankaccounts VALUES (NULL,223,"30066100410001126780124","X-Theatre","used"); +DROP TABLE IF EXISTS payment_reconcilations; CREATE TABLE payment_reconcilations ( id INTEGER PRIMARY KEY auto_increment, method_id INTEGER NOT NULL, @@ -68,11 +70,12 @@ UPDATE payment_transactions SET status = 'confirmed'; UPDATE payment_transactions SET amount=CONVERT(REPLACE(REPLACE(amount_tmp," EUR",""),",","."),DECIMAL(9,2)); ALTER TABLE payment_transactions ADD KEY method_id (method_id); ALTER TABLE payment_transactions ADD KEY ref (ref); -ALTER TABLE payment_transactions ADD UNIQUE KEY fullref (fullref); +# ALTER TABLE payment_transactions ADD UNIQUE KEY fullref (fullref); #fullref dupliqués : #select t1.* from payment_transactions as t1 join payment_transactions as t2 using(fullref) group by(t1.id) having count(*)!=1 order by fullref; ALTER TABLE payment_transactions DROP amount_tmp; +DROP TABLE IF EXISTS payment_transfers; CREATE TABLE payment_transfers ( id INTEGER PRIMARY KEY auto_increment, recongroup_id INTEGER NOT NULL, diff --git a/upgrade/1.0.1/update.sh b/upgrade/1.0.1/update.sh index 3d6c7b8..8368751 100755 --- a/upgrade/1.0.1/update.sh +++ b/upgrade/1.0.1/update.sh @@ -4,6 +4,7 @@ ########################################################### [ "$DATABASE" != "x4dat" ] || die "Cannot target x4dat" +copy_db confirm "* Running database upgrade scripts" mysql_run_directory . diff --git a/upgrade/inc/pervasive.sh b/upgrade/inc/pervasive.sh index bc369ce..d0a1992 100755 --- a/upgrade/inc/pervasive.sh +++ b/upgrade/inc/pervasive.sh @@ -66,6 +66,25 @@ function mysql_run() { echo "OK" } +function create_db() { + echo "* create database " + mysql_exec_nodb "CREATE DATABASE IF NOT EXISTS $DATABASE;" + mysql_exec_nodb "GRANT ALTER, CREATE, CREATE TEMPORARY TABLES, DELETE, DROP, EXECUTE, INDEX, INSERT, LOCK TABLES, SELECT, UPDATE ON $DATABASE.* TO 'web'@'localhost';" + mysql_exec_nodb "FLUSH PRIVILEGES;" + echo "OK" +} + +function copy_db() { + if [[ -n "$SOURCE_DATABASE" ]]; then + confirm "* copying database from $SOURCE_DATABASE to $DATABASE" + create_db + echo -n "* build database from dump " + ( mysqldump --add-drop-table -Q $SOURCE_DATABASE | $MYSQL $DATABASE ) \ + || die "ERROR" + echo "OK" + fi +} + function mysql_run_directory() { for sql in $1/*.sql ; do mysql_run $sql -- 2.1.4