From 23970975e358ea93624ca5c8559475e3a01bb1d6 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 17 Nov 2020 17:56:18 +1300 Subject: [PATCH] Bug 18050: DBRev 19.05.16.002 Signed-off-by: Aleisha Amohia (cherry picked from commit 026316d5515621aa3a096850754d2fae5b6f01dc) Signed-off-by: Victor Grousset/tuxayo --- Koha.pm | 2 +- .../bug_18050_aqbudget_constraint.perl | 40 ------------------- installer/data/mysql/updatedatabase.pl | 40 +++++++++++++++++++ 3 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_18050_aqbudget_constraint.perl diff --git a/Koha.pm b/Koha.pm index 9811a9c88c..5e51dc53ff 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "19.05.16.001"; +$VERSION = "19.05.16.002"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_18050_aqbudget_constraint.perl b/installer/data/mysql/atomicupdate/bug_18050_aqbudget_constraint.perl deleted file mode 100644 index 9912a71aac..0000000000 --- a/installer/data/mysql/atomicupdate/bug_18050_aqbudget_constraint.perl +++ /dev/null @@ -1,40 +0,0 @@ -$DBversion = 'XXX'; -if( CheckVersion( $DBversion ) ) { - my $count_missing_budget = $dbh->selectrow_arrayref(q| - SELECT COUNT(*) FROM aqbudgets ab WHERE NOT EXISTS - (SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id) - AND budget_period_id IS NOT NULL; - - |); - - my $message = ""; - if($count_missing_budget->[0] > 0) { - $dbh->do(q| - CREATE TABLE _bug_18050_aqbudgets AS - SELECT * FROM aqbudgets ab WHERE NOT EXISTS - (SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id) - |); - - $dbh->do(q| - UPDATE aqbudgets ab SET budget_period_id = NULL - WHERE NOT EXISTS - (SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id) - |); - $message = ". There are $count_missing_budget->[0] funds in your database that are not linked - to a valid budget. Setting invalid budget id (budget_period_id) to null. The table _bug_18050_aqbudgets - was created with original data. Please check that table and place valid ids in aqbudget table as soon as possible." - - } - - if ( !foreign_key_exists( 'aqbudgets', 'aqbudgetperiods_ibfk_1' ) ) { - $dbh->do(q| - ALTER TABLE aqbudgets ADD CONSTRAINT `aqbudgetperiods_ibfk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON UPDATE CASCADE ON DELETE CASCADE - |); - print "Upgrade to $DBversion done (Bug 18050 - Add FK constraint on aqbudgets.budget_period_id$message)\n"; - SetVersion( $DBversion ); - } else { - print "Upgrade to $DBversion done (Bug 18050 - FK constraint on aqbudgets.budget already exists)\n"; - SetVersion( $DBversion ); - } - -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 163c55c89f..93f04f44c0 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -19177,6 +19177,46 @@ if( CheckVersion( $DBversion ) ) { SetVersion( $DBversion ); } +$DBversion = '19.05.16.002'; +if( CheckVersion( $DBversion ) ) { + my $count_missing_budget = $dbh->selectrow_arrayref(q| + SELECT COUNT(*) FROM aqbudgets ab WHERE NOT EXISTS + (SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id) + AND budget_period_id IS NOT NULL; + + |); + + my $message = ""; + if($count_missing_budget->[0] > 0) { + $dbh->do(q| + CREATE TABLE _bug_18050_aqbudgets AS + SELECT * FROM aqbudgets ab WHERE NOT EXISTS + (SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id) + |); + + $dbh->do(q| + UPDATE aqbudgets ab SET budget_period_id = NULL + WHERE NOT EXISTS + (SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id) + |); + $message = ". There are $count_missing_budget->[0] funds in your database that are not linked + to a valid budget. Setting invalid budget id (budget_period_id) to null. The table _bug_18050_aqbudgets + was created with original data. Please check that table and place valid ids in aqbudget table as soon as possible." + + } + + if ( !foreign_key_exists( 'aqbudgets', 'aqbudgetperiods_ibfk_1' ) ) { + $dbh->do(q| + ALTER TABLE aqbudgets ADD CONSTRAINT `aqbudgetperiods_ibfk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON UPDATE CASCADE ON DELETE CASCADE + |); + print "Upgrade to $DBversion done (Bug 18050 - Add FK constraint on aqbudgets.budget_period_id$message)\n"; + SetVersion( $DBversion ); + } else { + print "Upgrade to $DBversion done (Bug 18050 - FK constraint on aqbudgets.budget already exists)\n"; + SetVersion( $DBversion ); + } +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5