Bug 33671: (follow-up) Disable FK check for column change
See also BZ report. As suggested by Tomas. NOTE: The dbrev is extended too for removing records with a failing guarantor_id foreign key (theoretically not present obviously). Test plan: 1) cp installer/data/mysql/db_revs/220600048.pl installer/data/mysql/atomicupdate/ 2) Run updatedatabase.pl 3) Remove copied file Bonus: Manually remove FK constraint before running updatedatabase. Insert a record with bad guarantor_id into relationships manually. Run the update again. You should not see the message that the constraint is removed. Is the bad record count reported and record removed? Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> [EDIT] Simplified. No longer removes the FK. Just disables during ALTER. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> (cherry picked from commit0397251ece
) Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> (cherry picked from commit4cdb3a57db
) Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
parent
f26621c8c4
commit
80fe98aff7
1 changed files with 9 additions and 4 deletions
|
@ -1,18 +1,23 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => 30472,
|
||||
bug_number => 30472, # adjusted on bug 33671
|
||||
description => "borrower_relationships.guarantor_id NOT NULL",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
||||
|
||||
# Delete 'empty' guarantors. No longer possible to add them via interface. Have no use.
|
||||
$dbh->do(q{
|
||||
DELETE FROM borrower_relationships WHERE guarantor_id IS NULL
|
||||
# Delete bad/empty guarantors. No longer possible to add them via interface. Have no use.
|
||||
my $cnt = $dbh->do(q{
|
||||
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;
|
||||
});
|
||||
say $out "Removed $cnt bad guarantor relationship records" if $cnt && $cnt =~ /^\d+$/;
|
||||
|
||||
# Make column NOT NULL, disable FK checks while doing so
|
||||
$dbh->do('SET FOREIGN_KEY_CHECKS=0');
|
||||
$dbh->do(q{
|
||||
ALTER TABLE borrower_relationships CHANGE COLUMN guarantor_id guarantor_id int(11) NOT NULL
|
||||
});
|
||||
$dbh->do('SET FOREIGN_KEY_CHECKS=1');
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue