Bug 42068: Bug 26993 (follow-up) Don't use FOREIGN_KEY_CHECKS
To test:
1 - Checkout 25.11.x - reset_all
2 - Enable StoreLastBorrower
3 - Issue an item
4 - Ensure item has a row in items_last_borrower
SELECT * FROM items_last_borrower
5 - Checkout main
6 - updatedatabase
7 - Try to delete any item, doesn't have to be the one you issued
DELETE FROM items WHERE itemnumber=93;
8 - ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`koha_kohadev`.`items_last_borrower`, CONSTRAINT `items_last_borrower_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE)
9 - repeat 1-5
10 - APPLY PATCH
11 - updatedatabase
12 - Try to delete any item
13 - Success!
14 - Delete the item you issued previously (in the staff interface on via mysql)
15 - Confirm no rows in items_last_borrower
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
ce09a18d56
commit
d69d218d68
|
|
@ -9,7 +9,14 @@ return {
|
|||
my ( $dbh, $out ) = @$args{qw(dbh out)};
|
||||
|
||||
if ( index_exists( 'items_last_borrower', 'itemnumber' ) ) {
|
||||
$dbh->do('SET FOREIGN_KEY_CHECKS=0');
|
||||
|
||||
# Drop existing foreign key
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE items_last_borrower
|
||||
DROP FOREIGN KEY items_last_borrower_ibfk_1
|
||||
}
|
||||
);
|
||||
|
||||
# Drop the unique index
|
||||
$dbh->do(
|
||||
|
|
@ -17,7 +24,16 @@ return {
|
|||
ALTER TABLE items_last_borrower DROP INDEX itemnumber
|
||||
}
|
||||
);
|
||||
$dbh->do('SET FOREIGN_KEY_CHECKS=1');
|
||||
|
||||
# Recreate foreign key
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE items_last_borrower
|
||||
ADD CONSTRAINT items_last_borrower_ibfk_1
|
||||
FOREIGN KEY (itemnumber) REFERENCES items (itemnumber)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE
|
||||
}
|
||||
);
|
||||
|
||||
say_success( $out, "Adjusted foreign key constraints on items_last_borrower table" );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue