From 361369f3ee3c1f1849fd6a255db47e0a338cf094 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 3 Oct 2018 11:04:45 -0300 Subject: [PATCH] Bug 18887: Make DB update idempotent --- installer/data/mysql/atomicupdate/bug_18887.perl | 39 +++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_18887.perl b/installer/data/mysql/atomicupdate/bug_18887.perl index 97eb1efa42..3d38b57e14 100644 --- a/installer/data/mysql/atomicupdate/bug_18887.perl +++ b/installer/data/mysql/atomicupdate/bug_18887.perl @@ -21,23 +21,28 @@ if( CheckVersion( $DBversion ) ) { }); } - $dbh->do(q{ - INSERT INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) - SELECT branchcode, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM branch_borrower_circ_rules - }); - - $dbh->do(q{ - INSERT INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) - SELECT NULL, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM default_borrower_circ_rules - }); - - $dbh->do(q{ - ALTER TABLE branch_borrower_circ_rules DROP COLUMN max_holds - }); - - $dbh->do(q{ - ALTER TABLE default_borrower_circ_rules DROP COLUMN max_holds - }); + + if (column_exists('branch_borrower_circ_rules', 'max_holds') ){ + $dbh->do(q{ + INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) + SELECT branchcode, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM branch_borrower_circ_rules + }); + + $dbh->do(q{ + ALTER TABLE branch_borrower_circ_rules DROP COLUMN max_holds + }); + } + + if (column_exists('default_borrower_circ_rules', 'max_holds') ){ + $dbh->do(q{ + INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) + SELECT NULL, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM default_borrower_circ_rules + }); + + $dbh->do(q{ + ALTER TABLE default_borrower_circ_rules DROP COLUMN max_holds + }); + } SetVersion( $DBversion ); print "Upgrade to $DBversion done (Bug 18887 - Introduce new table 'circulation_rules', use for 'max_holds' rules)\n"; -- 2.11.0