From: John Kingsnorth Date: Mon, 18 Jan 2021 11:16:27 +0000 (+0000) Subject: dev/core#2305 Fix schema differences in MariaDB 10.2.x+ X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=585a6418072f745dfdf9d0b62bff0650a60e04ec;p=civicrm-core.git dev/core#2305 Fix schema differences in MariaDB 10.2.x+ --- diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 6a75405d4c..0329a8851a 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -704,11 +704,13 @@ WHERE table_schema IN ('{$this->db}', '{$civiDB}')"; $logTableSpecs = $this->columnSpecsOf($logTable); $diff = ['ADD' => [], 'MODIFY' => [], 'OBSOLETE' => []]; - // columns to be added + + // Columns to be added $diff['ADD'] = array_diff(array_keys($civiTableSpecs), array_keys($logTableSpecs)); - // columns to be modified - // NOTE: we consider only those columns for modifications where there is a spec change, and that the column definition - // wasn't deliberately modified by fixTimeStampAndNotNullSQL() method. + + // Columns to be modified + // Only pick columns where there is a spec change and the column definition was not deliberately modified by + // fixTimeStampAndNotNullSQL() method, also accounting for differences in db version. foreach ($civiTableSpecs as $col => $colSpecs) { if (!isset($logTableSpecs[$col]) || !is_array($logTableSpecs[$col])) { $logTableSpecs[$col] = []; @@ -736,8 +738,10 @@ WHERE table_schema IN ('{$this->db}', '{$civiDB}')"; // if is-null property is different, and log table's column is NOT-NULL, surely consider the column $diff['MODIFY'][] = $col; } - elseif ($civiTableSpecs[$col]['COLUMN_DEFAULT'] != CRM_Utils_Array::value('COLUMN_DEFAULT', $logTableSpecs[$col]) && - !strstr($civiTableSpecs[$col]['COLUMN_DEFAULT'], 'TIMESTAMP') + elseif ( + $civiTableSpecs[$col]['COLUMN_DEFAULT'] != ($logTableSpecs[$col]['COLUMN_DEFAULT'] ?? NULL) + && !stristr($civiTableSpecs[$col]['COLUMN_DEFAULT'], 'timestamp') + && !($civiTableSpecs[$col]['COLUMN_DEFAULT'] === NULL && ($logTableSpecs[$col]['COLUMN_DEFAULT'] ?? NULL) === 'NULL') ) { // if default property is different, and its not about a timestamp column, consider it $diff['MODIFY'][] = $col;