From 7560fb7e144015f9f52818f6684a5bfd4d50b715 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 27 Apr 2021 12:52:26 +0000 Subject: [PATCH] Bug 17202: (follow-up) Conditionally add FK Signed-off-by: Jonathan Druart --- installer/data/mysql/atomicupdate/bug_17202.perl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_17202.perl b/installer/data/mysql/atomicupdate/bug_17202.perl index f0ddb49f64..85f3f41325 100644 --- a/installer/data/mysql/atomicupdate/bug_17202.perl +++ b/installer/data/mysql/atomicupdate/bug_17202.perl @@ -1,12 +1,14 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { - $dbh->do(q{ - DELETE FROM collections_tracking WHERE colId NOT IN ( SELECT colId FROM collections ) - }); - $dbh->do(q{ - ALTER TABLE collections_tracking - ADD CONSTRAINT `collectionst_ibfk_1` FOREIGN KEY (`colId`) REFERENCES `collections` (`colId`) ON DELETE CASCADE ON UPDATE CASCADE - }); + unless( foreign_key_exists( 'collections_tracking', 'collectionst_ibfk_1' ) ) { + $dbh->do(q{ + DELETE FROM collections_tracking WHERE colId NOT IN ( SELECT colId FROM collections ) + }); + $dbh->do(q{ + ALTER TABLE collections_tracking + ADD CONSTRAINT `collectionst_ibfk_1` FOREIGN KEY (`colId`) REFERENCES `collections` (`colId`) ON DELETE CASCADE ON UPDATE CASCADE + }); + } NewVersion( $DBversion, 17202, "Add FK constraint for collection to collections_tracking"); } -- 2.20.1