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

(-)a/installer/data/mysql/db_revs/220600048.pl (-5 / +9 lines)
Lines 1-18 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => 30472,
4
    bug_number => 30472, # adjusted on bug 33671
5
    description => "borrower_relationships.guarantor_id NOT NULL",
5
    description => "borrower_relationships.guarantor_id NOT NULL",
6
    up => sub {
6
    up => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
9
10
        # Delete 'empty' guarantors. No longer possible to add them via interface. Have no use.
10
        # Delete bad/empty guarantors. No longer possible to add them via interface. Have no use.
11
        $dbh->do(q{
11
        my $cnt = $dbh->do(q{
12
DELETE FROM borrower_relationships WHERE guarantor_id IS NULL
12
DELETE borrower_relationships FROM borrower_relationships LEFT JOIN borrowers bo ON bo.borrowernumber=guarantor_id WHERE guarantor_id IS NULL OR bo.borrowernumber IS NULL;
13
        });
13
        });
14
        say $out "Removed $cnt bad guarantor relationship records" if $cnt && $cnt =~ /^\d+$/;
15
16
        # Make column NOT NULL, disable FK checks while doing so
17
        $dbh->do('SET FOREIGN_KEY_CHECKS=0');
14
        $dbh->do(q{
18
        $dbh->do(q{
15
ALTER TABLE borrower_relationships CHANGE COLUMN guarantor_id guarantor_id int(11) NOT NULL
19
ALTER TABLE borrower_relationships CHANGE COLUMN guarantor_id guarantor_id int(11) NOT NULL
16
        });
20
        });
21
        $dbh->do('SET FOREIGN_KEY_CHECKS=1');
17
    },
22
    },
18
};
23
};
19
- 

Return to bug 33671