diff --git a/app/src/Lib/Match/MatchgridBuilder.php b/app/src/Lib/Match/MatchgridBuilder.php index 956fc5bb4..4f057c85c 100644 --- a/app/src/Lib/Match/MatchgridBuilder.php +++ b/app/src/Lib/Match/MatchgridBuilder.php @@ -105,6 +105,7 @@ protected function configToSchema($dbc, \Cake\Datasource\EntityInterface $Matchg // Track which attributes need case insensitive indexes $ciAttrs = []; + if($indexes) { // Since index names need to be unique across the schema, we'll use the // matchgrid ID to make the names unique. @@ -165,15 +166,19 @@ protected function configToSchema($dbc, \Cake\Datasource\EntityInterface $Matchg // currently the least painful way to do it $sql = rtrim($sql, ")") . " NULLS FIRST)"; } elseif(preg_match("/^CREATE INDEX (\w+) ON .*/", $sql, $matches)) { - $attr = $ciAttrs[ $matches[1] ]; - // Not ideal to hardcode SQL, but this should be pretty portable. - // Note the validation rule for table_name and attr is pretty restrictive, - // so we don't need to SQL escape them. Similarly, we create the index - // name above. - // We use IF NOT EXISTS to avoid errors on rebuilding the matchgrid, - // however a better long term solution would be to add native support to - // DBAL for expression in index creation (CO-2217). - $sql = "CREATE INDEX IF NOT EXISTS " . $matches[1] . " ON " . $Matchgrid->prefixed_table_name . " (LOWER(" . $attr . "))"; + // If we're creating an index on a case insensitive attribute, swap out + // the SQL for a lower cased index + if(!empty($ciAttrs[ $matches[1] ])) { + $attr = $ciAttrs[ $matches[1] ]; + // Not ideal to hardcode SQL, but this should be pretty portable. + // Note the validation rule for table_name and attr is pretty restrictive, + // so we don't need to SQL escape them. Similarly, we create the index + // name above. + // We use IF NOT EXISTS to avoid errors on rebuilding the matchgrid, + // however a better long term solution would be to add native support to + // DBAL for expression in index creation (CO-2217). + $sql = "CREATE INDEX IF NOT EXISTS " . $matches[1] . " ON " . $Matchgrid->prefixed_table_name . " (LOWER(" . $attr . "))"; + } } $stmt = $dbc->query($sql);