Bug 30490: Adjust constraint itemtypes.itemtypes_ibfk_1

Change from CASCADE to restrict.
In harmony with dbrev 20.06.00.022.

Test plan:
Run the dbrev.
Bonus:
update itemtypes set parent_type='VM' where itemtype='CF';
delete from itemtypes where itemtype='VM';
=> ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`koha_myclone`.`itemtypes`, CONSTRAINT `itemtypes_ibfk_1` FOREIGN KEY (`parent_type`) REFERENCES `itemtypes` (`itemtype`))

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2022-08-23 13:00:17 +00:00 committed by Tomas Cohen Arazi
parent ca338bae1e
commit 9b018fc6de
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,18 @@
use Modern::Perl;
return {
bug_number => 30490,
description => "Adjust FK constraint for parent item type",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
if( foreign_key_exists('itemtypes', 'itemtypes_ibfk_1') ) {
$dbh->do(q{
alter table itemtypes drop foreign key itemtypes_ibfk_1;
});
}
$dbh->do(q{
alter table itemtypes add foreign key itemtypes_ibfk_1 (`parent_type`) REFERENCES `itemtypes` (`itemtype`);
});
},
};

View File

@ -3344,7 +3344,7 @@ CREATE TABLE `itemtypes` (
PRIMARY KEY (`itemtype`),
UNIQUE KEY `itemtype` (`itemtype`),
KEY `itemtypes_ibfk_1` (`parent_type`),
CONSTRAINT `itemtypes_ibfk_1` FOREIGN KEY (`parent_type`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE
CONSTRAINT `itemtypes_ibfk_1` FOREIGN KEY (`parent_type`) REFERENCES `itemtypes` (`itemtype`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;