From 36a37b245d8debe63e39c9eb551f3c169e68eada Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Sep 2021 13:57:06 +0200 Subject: [PATCH] Bug 28972: Make DB rev idempotent Signed-off-by: Jonathan Druart --- installer/data/mysql/atomicupdate/bug_28972.pl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_28972.pl b/installer/data/mysql/atomicupdate/bug_28972.pl index c475ae5fe5..12f52eac15 100755 --- a/installer/data/mysql/atomicupdate/bug_28972.pl +++ b/installer/data/mysql/atomicupdate/bug_28972.pl @@ -6,10 +6,17 @@ return { up => sub { my ($args) = @_; my ($dbh, $out) = @$args{qw(dbh out)}; - $dbh->do(q{ - ALTER TABLE tmp_holdsqueue - ADD CONSTRAINT `tmp_holdsqueue_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE, - ADD CONSTRAINT `tmp_holdsqueue_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE - }); + unless ( foreign_key_exists('tmp_holdsqueue', 'tmp_holdsqueue_ibfk_2') ) { + $dbh->do(q{ + ALTER TABLE tmp_holdsqueue + ADD CONSTRAINT `tmp_holdsqueue_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE + }); + } + unless ( foreign_key_exists('tmp_holdsqueue', 'tmp_holdsqueue_ibfk_2') ) { + $dbh->do(q{ + ALTER TABLE tmp_holdsqueue + ADD CONSTRAINT `tmp_holdsqueue_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE + }); + } }, } -- 2.39.5