From 43475232c3ebbb57d0090548105efd98648cad8a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 19 Aug 2019 07:22:50 -0300 Subject: [PATCH] Bug 14570: Handle missing 'relationship' in atomicupdate (bad data) This patch adds two steps to the upgrade process: - Handle the pathologic case in which there's a guarantorid and no 'relationship'. - Performs a cleanup on the relevant columns when the guarantor data contains a guarantorid, and is then migrated into the borrower_relationships table. The original code left the information in the borrowers table, so no clear separation between guarantors as patrons and the virtual ones. Signed-off-by: Tomas Cohen Arazi --- installer/data/mysql/atomicupdate/bug_14570.perl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/installer/data/mysql/atomicupdate/bug_14570.perl b/installer/data/mysql/atomicupdate/bug_14570.perl index c266c9b669..e3f9a6465c 100644 --- a/installer/data/mysql/atomicupdate/bug_14570.perl +++ b/installer/data/mysql/atomicupdate/bug_14570.perl @@ -22,11 +22,27 @@ if( CheckVersion( $DBversion ) ) { SET borrowers.guarantorid = NULL WHERE guarantor.borrowernumber IS NULL; }); + # Bad data handling: guarantorid IS NOT NULL AND relationship IS NULL + $dbh->do(q{ + UPDATE borrowers + SET relationship = '_bad_data' + WHERE guarantorid IS NOT NULL AND + relationship IS NULL + }); + $dbh->do(q{ INSERT INTO borrower_relationships ( guarantor_id, guarantee_id, relationship ) SELECT guarantorid, borrowernumber, relationship FROM borrowers WHERE guarantorid IS NOT NULL; }); + # Clean migrated guarantor data + $dbh->do(q{ + UPDATE borrowers + SET contactname=NULL, + contactfirstname=NULL, + relationship=NULL + WHERE guarantorid IS NOT NULL + }); } if( column_exists( 'borrowers', 'guarantorid' ) ) { -- 2.22.1