From fb0a659684a70204c1922675df18efca257bddd9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Nov 2020 15:15:02 +0100 Subject: [PATCH] Bug 24658: (bug 22008 follow-up) Correct update DB entry 18.12.00.031 If the original constraint does not exist, the second one is not added. Test plan: 1. checkout dbrev 18.12.00.030 2. Remove the constraint: ALTER TABLE accountlines DROP FOREIGN KEY accountlines_ibfk_2 3. checkout master 4. % updatedatabase => The constraint accountlines_ibfk_items is not added 5. Repeat 1 to 4 => The constraint is added correctly Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- installer/data/mysql/updatedatabase.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 6d96ca6cb7..8db165a434 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -17809,8 +17809,10 @@ if( CheckVersion( $DBversion ) ) { } # Rename accountlines_ibfk_2 to accountlines_ibfk_items - if ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_2' ) && !foreign_key_exists( 'accountlines', 'accountlines_ibfk_items' ) ) { + if ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_2' ) ) { $dbh->do("ALTER TABLE accountlines DROP FOREIGN KEY accountlines_ibfk_2"); + } + unless ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_items' ) ) { $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE"); } -- 2.39.5