From 364ada88b03ec592958902566cabf64d1d96192f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 23 Apr 2024 16:43:12 +0100 Subject: [PATCH] Bug 32132: (RM follow-up) Merge supplimentary db update This patch merges the logic from the supplimentary database update that was requested into the original DB update revision making the update more reliable. Signed-off-by: Martin Renvoize --- .../data/mysql/atomicupdate/bug_32132.pl | 31 ------------------- installer/data/mysql/db_revs/231200023.pl | 21 +++++++++++-- 2 files changed, 18 insertions(+), 34 deletions(-) delete mode 100755 installer/data/mysql/atomicupdate/bug_32132.pl diff --git a/installer/data/mysql/atomicupdate/bug_32132.pl b/installer/data/mysql/atomicupdate/bug_32132.pl deleted file mode 100755 index d5a24e5e59..0000000000 --- a/installer/data/mysql/atomicupdate/bug_32132.pl +++ /dev/null @@ -1,31 +0,0 @@ -use Modern::Perl; - -return { - bug_number => "32132", - description => "Update NULL values on aqbudgets.budget_period_id", - up => sub { - my ($args) = @_; - my ( $dbh, $out ) = @$args{qw(dbh out)}; - - # Do you stuffs here - my $count_sql = q{SELECT COUNT(*) FROM aqbudgets WHERE budget_period_id IS NULL}; - my ($count) = $dbh->selectrow_array($count_sql); - if ($count) { - $dbh->do( - q{INSERT IGNORE INTO aqbudgetperiods (budget_period_startdate, budget_period_enddate, budget_period_active, budget_period_description, budget_period_locked) VALUES (curdate(), curdate(), 0, "Budget for funds without budget", 1)} - ); - say $out "Added dummy budget period"; - - my $aqbp_sql = - q{SELECT budget_period_id FROM aqbudgetperiods WHERE budget_period_description = "Budget for funds without budget"}; - my ($aqbp_id) = $dbh->selectrow_array($aqbp_sql); - - $dbh->do( q{UPDATE aqbudgets SET budget_period_id = ? WHERE budget_period_id IS NULL}, undef, $aqbp_id ); - say $out "Updated columns aqbudgets.budget_period_id with value NULL"; - say $out - "There were $count budget(s) without budget_period_id. They all have been updated to be under budget called 'Budget for funds without budget' (id $aqbp_id)."; - } else { - say $out "No budget without budget_period_id found."; - } - }, -}; diff --git a/installer/data/mysql/db_revs/231200023.pl b/installer/data/mysql/db_revs/231200023.pl index da631191fe..7fa58207f3 100755 --- a/installer/data/mysql/db_revs/231200023.pl +++ b/installer/data/mysql/db_revs/231200023.pl @@ -8,10 +8,25 @@ return { my ( $dbh, $out ) = @$args{qw(dbh out)}; # Do you stuffs here - $dbh->do(q{ALTER TABLE aqbudgets MODIFY COLUMN `budget_period_id` INT(11) NOT NULL}); + my $count_sql = q{SELECT COUNT(*) FROM aqbudgets WHERE budget_period_id IS NULL}; + my ($count) = $dbh->selectrow_array($count_sql); + if ($count) { + $dbh->do( + q{INSERT IGNORE INTO aqbudgetperiods (budget_period_startdate, budget_period_enddate, budget_period_active, budget_period_description, budget_period_locked) VALUES (curdate(), curdate(), 0, "Budget for funds without budget", 1)} + ); + say $out "Added dummy budget period"; + + my $aqbp_sql = + q{SELECT budget_period_id FROM aqbudgetperiods WHERE budget_period_description = "Budget for funds without budget"}; + my ($aqbp_id) = $dbh->selectrow_array($aqbp_sql); - # Print useful stuff here - # tables + $dbh->do( q{UPDATE aqbudgets SET budget_period_id = ? WHERE budget_period_id IS NULL}, undef, $aqbp_id ); + say $out "Updated columns aqbudgets.budget_period_id with value NULL"; + say $out + "There were $count budget(s) without budget_period_id. They all have been updated to be under budget called 'Budget for funds without budget' (id $aqbp_id)."; + } + + $dbh->do(q{ALTER TABLE aqbudgets MODIFY COLUMN `budget_period_id` INT(11) NOT NULL}); say $out "Updated aqbudgets.budget_period_id to NOT accept NULL values"; }, }; -- 2.39.5