diff --git a/installer/data/mysql/atomicupdate/bug_30451_do_not_delete_orders_with_subscription.pl b/installer/data/mysql/atomicupdate/bug_30451_do_not_delete_orders_with_subscription.pl new file mode 100755 index 0000000000..bb3b7747fc --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_30451_do_not_delete_orders_with_subscription.pl @@ -0,0 +1,22 @@ +use Modern::Perl; + +return { + bug_number => "30451", + description => "Update FK constraint on aqorders.subscriptionid to ON DELETE SET NULL", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + if ( foreign_key_exists( 'aqorders', 'aqorders_subscriptionid' ) ) { + $dbh->do(q{ + ALTER TABLE aqorders + DROP FOREIGN KEY aqorders_subscriptionid + }); + } + $dbh->do(q{ + ALTER TABLE aqorders + ADD CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES subscription(`subscriptionid`) ON DELETE SET NULL ON UPDATE CASCADE + }); + say $out "Update FK constraint on subscriptionid"; + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index ba5305fd30..34aca0332b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -707,7 +707,7 @@ CREATE TABLE `aqorders` ( CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `aqorders_ibfk_3` FOREIGN KEY (`invoiceid`) REFERENCES `aqinvoices` (`invoiceid`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */;