From 475486781fec55b6a6bd62afd5f69ff5fdafd632 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 13 Jul 2022 18:11:34 +0100 Subject: [PATCH] Bug 28854: (follow-up) Replace unique constraint in return claims This patch fixes the failing test for the return claims api. We add a new unique constraint to replace the one we removed earlier in the patchset. One should not be able to create a duplicate return claim for the same issue of an item. Test plan 1) Run the database update 2) Confirm that t/db_dependent/api/v1/return_claims.t now passes 3) Confirm that t/db_dependent/api/v1/items.t continues to pass 4) Bonus points, confirm that bundle checkin still works when items are missing Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- installer/data/mysql/atomicupdate/bug_28854.pl | 17 +++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + 2 files changed, 18 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_28854.pl diff --git a/installer/data/mysql/atomicupdate/bug_28854.pl b/installer/data/mysql/atomicupdate/bug_28854.pl new file mode 100644 index 0000000000..c6eb44ae95 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_28854.pl @@ -0,0 +1,17 @@ +use Modern::Perl; + +return { + bug_number => "28854", + description => "Add new unique index to return claims", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + if ( !unique_key_exists('return_claims', 'item_issue') ) { + $dbh->do(q{ + ALTER TABLE return_claims + ADD UNIQUE KEY item_issue (`itemnumber`,`issue_id`) + }); + say $out "item_issue index added to return_claims"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3227ab27f1..b52213f476 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4514,6 +4514,7 @@ CREATE TABLE `return_claims` ( `resolved_on` timestamp NULL DEFAULT NULL COMMENT 'Time and date the claim was resolved', `resolved_by` int(11) DEFAULT NULL COMMENT 'ID of the staff member that resolved the claim', PRIMARY KEY (`id`), + UNIQUE KEY `item_issue` (`itemnumber`, `issue_id`), KEY `itemnumber` (`itemnumber`), KEY `rc_borrowers_ibfk` (`borrowernumber`), KEY `rc_created_by_ibfk` (`created_by`), -- 2.39.5