Line 0
Link Here
|
0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
|
3 |
return { |
4 |
bug_number => "32132", |
5 |
description => "Update NULL values on aqbudgets.budget_period_id", |
6 |
up => sub { |
7 |
my ($args) = @_; |
8 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
9 |
|
10 |
# Do you stuffs here |
11 |
my $count_sql = q{SELECT COUNT(*) FROM aqbudgets WHERE budget_period_id IS NULL}; |
12 |
my ($count) = $dbh->selectrow_array($count_sql); |
13 |
if ($count) { |
14 |
$dbh->do( |
15 |
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)} |
16 |
); |
17 |
say $out "Added dummy budget period"; |
18 |
|
19 |
my $aqbp_sql = |
20 |
q{SELECT budget_period_id FROM aqbudgetperiods WHERE budget_period_description = "Budget for funds without budget"}; |
21 |
my ($aqbp_id) = $dbh->selectrow_array($aqbp_sql); |
22 |
|
23 |
$dbh->do( q{UPDATE aqbudgets SET budget_period_id = ? WHERE budget_period_id IS NULL}, undef, $aqbp_id ); |
24 |
say $out "Updated columns aqbudgets.budget_period_id with value NULL"; |
25 |
say $out |
26 |
"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)."; |
27 |
} else { |
28 |
say $out "No budget without budget_period_id found."; |
29 |
} |
30 |
}, |
31 |
}; |