From 3e364dd3d2af6d4cef351594c5e34f221c835d1b Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 3 Nov 2021 16:53:47 +0000 Subject: [PATCH] Bug 29409: Check for data that violates a constraint to avoid update problems MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Joonas Kylmälä Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit e4455a589372e3205f9a7456478ad4585c90bedb) Signed-off-by: Lucas Gass (cherry picked from commit 6ea331417ea4a114ab9b5aec2a7885118942be21) Signed-off-by: Arthur Suzuki --- installer/data/mysql/updatedatabase.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index bf8fc0a946..ca1ff46afb 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -23195,6 +23195,11 @@ if( CheckVersion( $DBversion ) ) { ALTER TABLE letter ADD CONSTRAINT message_transport_type_fk FOREIGN KEY (message_transport_type) REFERENCES message_transport_types(message_transport_type) ON DELETE CASCADE ON UPDATE CASCADE } ); + # Foreign keys should prevent this, however, it has been found in many production databases + $dbh->do( q{ + DELETE borrower_message_transport_preferences FROM borrower_message_transport_preferences LEFT JOIN borrower_message_preferences USING (borrower_message_preference_id) WHERE borrower_message_preferences.borrower_message_preference_id IS NULL + } ); + $dbh->do(q{ UPDATE message_transport_types SET message_transport_type = "itiva" WHERE message_transport_type = "phone" }); -- 2.39.5