Bug 37000: (Bug 36120 follow-up) Improve reliability of database update
This patch adds a series of fallthroughs to ensure pickup_library_id is always set prior to adding the NOT NULL constraint. We initially only looked at items.homebranch but as that's a nullable field itself, we now look at items.holdingbranch before finally defaulting to the first available branch in the branches table in the worst case. Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz> Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
b9ca6b4a36
commit
8cedcfd5c8
1 changed files with 34 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
use Modern::Perl;
|
||||
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
|
||||
|
||||
return {
|
||||
bug_number => "36120",
|
||||
|
@ -14,24 +15,49 @@ return {
|
|||
ADD COLUMN `pickup_library_id` varchar(10) DEFAULT NULL COMMENT 'Identifier for booking pickup library' AFTER `item_id`,
|
||||
ADD CONSTRAINT `bookings_ibfk_4` FOREIGN KEY (`pickup_library_id`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
}
|
||||
);
|
||||
) == 1
|
||||
&& say_success( $out, "Added column 'bookings.pickup_library_id'" );
|
||||
|
||||
say $out "Added column 'bookings.pickup_library_id'";
|
||||
|
||||
$dbh->do(
|
||||
my $updated = $dbh->do(
|
||||
q{UPDATE bookings JOIN items ON bookings.item_id = items.itemnumber SET bookings.pickup_library_id = items.homebranch }
|
||||
);
|
||||
|
||||
say $out "Set existing bookings pickup location to item homebranch";
|
||||
if ( $updated != '0E0' ) {
|
||||
say_success( $out, "Set $updated existing bookings pickup location to item homebranch" );
|
||||
} else {
|
||||
say_info( $out, "No bookings found that need updating to include a pickup library" );
|
||||
}
|
||||
|
||||
$updated = $dbh->do(
|
||||
q{UPDATE bookings JOIN items ON bookings.item_id = items.itemnumber SET pickup_library_id = items.holdingbranch WHERE pickup_library_id IS NULL}
|
||||
);
|
||||
|
||||
if ( $updated != '0E0' ) {
|
||||
say_success(
|
||||
$out,
|
||||
"Set $updated existing bookings pickup location to item holdingbranch where items.homebranch was null"
|
||||
);
|
||||
}
|
||||
|
||||
my ($firstBranch) = $dbh->selectrow_array(q{SELECT branchcode FROM branches LIMIT 1});
|
||||
$updated = $dbh->do(
|
||||
q{UPDATE bookings SET pickup_library_id = ? WHERE pickup_library_id IS NULL}, undef,
|
||||
$firstBranch
|
||||
);
|
||||
|
||||
if ( $updated != '0E0' ) {
|
||||
say_warning(
|
||||
$out,
|
||||
"Some $updated bookings still had a null pickup location value so we have set them to $firstBranch"
|
||||
);
|
||||
}
|
||||
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE bookings
|
||||
MODIFY pickup_library_id varchar(10) NOT NULL COMMENT 'Identifier for booking pickup library'
|
||||
}
|
||||
);
|
||||
|
||||
say $out "Set pickup_library_id to NOT NULL";
|
||||
) == 1 && say_success( $out, "Updated column 'bookings.pickup_library_id' to NOT NULL" );
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue