From 13b87f879a85c43516020646fbee882cc9a83679 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Sat, 2 Mar 2019 10:14:48 -0300 Subject: [PATCH] Bug 18925: (QA follow-up) Make DB update idempotent Signed-off-by: Tomas Cohen Arazi Signed-off-by: Josef Moravec --- installer/data/mysql/atomicupdate/bug_18925.perl | 52 +++++++++++++----------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_18925.perl b/installer/data/mysql/atomicupdate/bug_18925.perl index 3e5075fbe5..89d943f597 100644 --- a/installer/data/mysql/atomicupdate/bug_18925.perl +++ b/installer/data/mysql/atomicupdate/bug_18925.perl @@ -1,31 +1,35 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { - if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) { - $dbh->do(" - INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, branchcode, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) - FROM branch_borrower_circ_rules - "); - $dbh->do(" - INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, branchcode, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) - FROM branch_borrower_circ_rules - "); - $dbh->do("DROP TABLE branch_borrower_circ_rules"); + if ( TableExists( 'branch_borrower_circ_rules' ) ) { + if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) + FROM branch_borrower_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) + FROM branch_borrower_circ_rules + "); + $dbh->do("DROP TABLE branch_borrower_circ_rules"); + } } - if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) { - $dbh->do(" - INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, NULL, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) - FROM default_borrower_circ_rules - "); - $dbh->do(" - INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, NULL, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) - FROM default_borrower_circ_rules - "); - $dbh->do("DROP TABLE default_borrower_circ_rules"); + if ( TableExists( 'default_borrower_circ_rules' ) ) { + if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, NULL, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) + FROM default_borrower_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, NULL, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) + FROM default_borrower_circ_rules + "); + $dbh->do("DROP TABLE default_borrower_circ_rules"); + } } if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) { -- 2.11.0