View | Details | Raw Unified | Return to bug 36993
Collapse All | Expand All

(-)a/installer/data/mysql/db_revs/231200023.pl (-3 / +14 lines)
Lines 8-14 return { Link Here
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        # Do you stuffs here
10
        # Do you stuffs here
11
        my $count_sql = q{SELECT COUNT(*) FROM aqbudgets WHERE budget_period_id IS NULL};
11
        my $count_sql =
12
            q{SELECT COUNT(*) FROM aqbudgets WHERE budget_period_id IS NULL OR budget_period_id NOT IN(SELECT budget_period_id FROM aqbudgetperiods)};
12
        my ($count) = $dbh->selectrow_array($count_sql);
13
        my ($count) = $dbh->selectrow_array($count_sql);
13
        if ($count) {
14
        if ($count) {
14
            $dbh->do(
15
            $dbh->do(
Lines 20-32 return { Link Here
20
                q{SELECT budget_period_id FROM aqbudgetperiods WHERE budget_period_description = "Budget for funds without budget"};
21
                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
            my ($aqbp_id) = $dbh->selectrow_array($aqbp_sql);
22
23
23
            $dbh->do( q{UPDATE aqbudgets SET budget_period_id = ? WHERE budget_period_id IS NULL}, undef, $aqbp_id );
24
            $dbh->do(
25
                q{UPDATE aqbudgets SET budget_period_id = ? WHERE budget_period_id IS NULL OR budget_period_id NOT IN(SELECT budget_period_id FROM aqbudgetperiods)},
26
                undef, $aqbp_id
27
            );
24
            say $out "Updated columns aqbudgets.budget_period_id with value NULL";
28
            say $out "Updated columns aqbudgets.budget_period_id with value NULL";
25
            say $out
29
            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).";
30
                "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
        }
31
        }
28
32
33
        $dbh->do(q{ALTER TABLE aqbudgets DROP FOREIGN KEY aqbudgetperiods_ibfk_1});
34
        say $out "Dropped foreign key aqbudgetperiods_ibfk_1";
35
29
        $dbh->do(q{ALTER TABLE aqbudgets MODIFY COLUMN `budget_period_id` INT(11) NOT NULL});
36
        $dbh->do(q{ALTER TABLE aqbudgets MODIFY COLUMN `budget_period_id` INT(11) NOT NULL});
30
        say $out "Updated aqbudgets.budget_period_id to NOT accept NULL values";
37
        say $out "Updated aqbudgets.budget_period_id to NOT accept NULL values";
38
39
        $dbh->do(
40
            q{ALTER TABLE aqbudgets ADD CONSTRAINT `aqbudgetperiods_ibfk_1` FOREIGN KEY (`budget_period_id`) REFERENCES aqbudgetperiods(`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE}
41
        );
42
        say $out "Readded foreign key aqbudgetperiods_ibfk_1";
31
    },
43
    },
32
};
44
};
33
- 

Return to bug 36993