Bug 18928: (follow-up) Make DB update idempotent

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Agustin Moyano <agustinmoyano@theke.io>
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2019-03-06 09:51:28 -03:00 committed by Martin Renvoize
parent f261dc4df6
commit d2cb9fdaff
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 77 additions and 68 deletions

View File

@ -1,79 +1,88 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
if ( column_exists( 'default_circ_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, NULL, 'holdallowed', holdallowed
FROM default_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, NULL, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM default_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, NULL, 'returnbranch', returnbranch
FROM default_circ_rules
");
$dbh->do("DROP TABLE default_circ_rules");
if ( TableExists('default_circ_rules') ) {
if ( column_exists( 'default_circ_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, NULL, 'holdallowed', holdallowed
FROM default_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, NULL, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM default_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, NULL, 'returnbranch', returnbranch
FROM default_circ_rules
");
$dbh->do("DROP TABLE default_circ_rules");
}
}
if ( column_exists( 'default_branch_circ_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, NULL, 'holdallowed', holdallowed
FROM default_branch_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, NULL, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM default_branch_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, NULL, 'returnbranch', returnbranch
FROM default_branch_circ_rules
");
$dbh->do("DROP TABLE default_branch_circ_rules");
if ( TableExists('default_branch_circ_rules') ) {
if ( column_exists( 'default_branch_circ_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, NULL, 'holdallowed', holdallowed
FROM default_branch_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, NULL, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM default_branch_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, NULL, 'returnbranch', returnbranch
FROM default_branch_circ_rules
");
$dbh->do("DROP TABLE default_branch_circ_rules");
}
}
if ( column_exists( 'branch_item_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, itemtype, 'holdallowed', holdallowed
FROM branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, itemtype, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, itemtype, 'returnbranch', returnbranch
FROM branch_item_rules
");
$dbh->do("DROP TABLE branch_item_rules");
if ( TableExists('branch_item_rules') ) {
if ( column_exists( 'branch_item_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, itemtype, 'holdallowed', holdallowed
FROM branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, itemtype, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, branchcode, itemtype, 'returnbranch', returnbranch
FROM branch_item_rules
");
$dbh->do("DROP TABLE branch_item_rules");
}
}
if ( column_exists( 'default_branch_item_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, itemtype, 'holdallowed', holdallowed
FROM default_branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, itemtype, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM default_branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, itemtype, 'returnbranch', returnbranch
FROM default_branch_item_rules
");
$dbh->do("DROP TABLE default_branch_item_rules");
if ( TableExists('default_branch_item_rules') ) {
if ( column_exists( 'default_branch_item_rules', 'holdallowed' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, itemtype, 'holdallowed', holdallowed
FROM default_branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, itemtype, 'hold_fulfillment_policy', hold_fulfillment_policy
FROM default_branch_item_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT NULL, NULL, itemtype, 'returnbranch', returnbranch
FROM default_branch_item_rules
");
$dbh->do("DROP TABLE default_branch_item_rules");
}
}
SetVersion( $DBversion );