Bug 34520: Fix FK for item_groups in reserves for new installations
There was a discrepancy between the database update for reserves and the kohastructure.sql definition. This makes sure that the FK is always "ON DELETE SET NULL". To test: * Before applying this path * sudo koha-mysql kohadev * show create table reserves; CONSTRAINT `reserves_ibfk_ig` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE CASCADE ON UPDATE CASCADE * Apply patch * Run database update * Check database again: CONSTRAINT `reserves_ibfk_ig` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE SET NULL ON UPDATE CASCADE * reset_all (create a new database) * Check database again: CONSTRAINT `reserves_ibfk_ig` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE SET NULL ON UPDATE CASCADE Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> (cherry picked from commit6dd4626711
) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> (cherry picked from commitd0090275b0
) Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
parent
9cca154793
commit
938ff88906
2 changed files with 31 additions and 1 deletions
30
installer/data/mysql/atomicupdate/bug_34520_item_groups_fk.pl
Executable file
30
installer/data/mysql/atomicupdate/bug_34520_item_groups_fk.pl
Executable file
|
@ -0,0 +1,30 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => "34520",
|
||||
description => "Correct item_groups FK in reserves table",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ( $dbh, $out ) = @$args{qw(dbh out)};
|
||||
|
||||
if ( foreign_key_exists( 'reserves', 'reserves_ibfk_ig' ) ) {
|
||||
$dbh->do(
|
||||
q|
|
||||
ALTER TABLE reserves
|
||||
DROP FOREIGN KEY reserves_ibfk_ig
|
||||
|
|
||||
);
|
||||
|
||||
$dbh->do(
|
||||
q|
|
||||
ALTER TABLE reserves
|
||||
ADD CONSTRAINT reserves_ibfk_ig
|
||||
FOREIGN KEY (item_group_id)
|
||||
REFERENCES item_groups (item_group_id) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
|
|
||||
);
|
||||
}
|
||||
|
||||
say $out "FK 'reserves_ibfk_ig' on reserves updated to ON DELETE SET NULL";
|
||||
},
|
||||
};
|
|
@ -4961,7 +4961,7 @@ CREATE TABLE `reserves` (
|
|||
CONSTRAINT `reserves_ibfk_4` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `reserves_ibfk_5` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `reserves_ibfk_6` FOREIGN KEY (`desk_id`) REFERENCES `desks` (`desk_id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `reserves_ibfk_ig` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
CONSTRAINT `reserves_ibfk_ig` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
|
Loading…
Reference in a new issue