From a466febe532d591a584ec974ace8d9ac1bb9a5dc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 24 Feb 2026 13:03:55 +0000 Subject: [PATCH] Bug 14962: (QA follow-up) Change branch/itype FK on displays to ON DELETE SET NULL The foreign keys from displays.display_branch, display_holding_branch, and display_itype used ON DELETE CASCADE, which would silently delete entire displays when an admin removes a branch or item type. These columns are optional configuration references, not ownership relationships (all are nullable DEFAULT NULL). Use ON DELETE SET NULL so the display is preserved and the reference is simply cleared, which is consistent with how items.homebranch references branches. Update atomicupdate, kohastructure.sql, and the DBIC schema to match. Sponsored-by: ByWater Solutions Signed-of-by: Martin Renvoize --- Koha/Schema/Result/Display.pm | 6 +++--- .../data/mysql/atomicupdate/bug_14962-temporary_shelves.pl | 6 +++--- installer/data/mysql/kohastructure.sql | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Koha/Schema/Result/Display.pm b/Koha/Schema/Result/Display.pm index 701781f3ac7..3cf2886f525 100644 --- a/Koha/Schema/Result/Display.pm +++ b/Koha/Schema/Result/Display.pm @@ -205,7 +205,7 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, join_type => "LEFT", - on_delete => "CASCADE", + on_delete => "SET NULL", on_update => "CASCADE", }, ); @@ -225,7 +225,7 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, join_type => "LEFT", - on_delete => "CASCADE", + on_delete => "SET NULL", on_update => "CASCADE", }, ); @@ -260,7 +260,7 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, join_type => "LEFT", - on_delete => "CASCADE", + on_delete => "SET NULL", on_update => "CASCADE", }, ); diff --git a/installer/data/mysql/atomicupdate/bug_14962-temporary_shelves.pl b/installer/data/mysql/atomicupdate/bug_14962-temporary_shelves.pl index 102124658b4..e421ac97363 100755 --- a/installer/data/mysql/atomicupdate/bug_14962-temporary_shelves.pl +++ b/installer/data/mysql/atomicupdate/bug_14962-temporary_shelves.pl @@ -30,9 +30,9 @@ return { KEY `display_branch` (`display_branch`), KEY `display_holding_branch` (`display_holding_branch`), KEY `display_itype` (`display_itype`), - CONSTRAINT `displays_ibfk_1` FOREIGN KEY (`display_branch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `displays_ibfk_2` FOREIGN KEY (`display_holding_branch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `displays_ibfk_3` FOREIGN KEY (`display_itype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `displays_ibfk_1` FOREIGN KEY (`display_branch`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `displays_ibfk_2` FOREIGN KEY (`display_holding_branch`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `displays_ibfk_3` FOREIGN KEY (`display_itype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci } ); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index aec552a26c9..e3bad779541 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2912,9 +2912,9 @@ CREATE TABLE `displays` ( KEY `display_branch` (`display_branch`), KEY `display_holding_branch` (`display_holding_branch`), KEY `display_itype` (`display_itype`), - CONSTRAINT `displays_ibfk_1` FOREIGN KEY (`display_branch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `displays_ibfk_2` FOREIGN KEY (`display_holding_branch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `displays_ibfk_3` FOREIGN KEY (`display_itype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `displays_ibfk_1` FOREIGN KEY (`display_branch`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `displays_ibfk_2` FOREIGN KEY (`display_holding_branch`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `displays_ibfk_3` FOREIGN KEY (`display_itype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- 2.53.0