diff --git a/app/config/schema/schema.json b/app/config/schema/schema.json index bae9ccfdc..b1f53456d 100644 --- a/app/config/schema/schema.json +++ b/app/config/schema/schema.json @@ -442,7 +442,8 @@ "identifiers_i1": { "columns": [ "identifier", "type_id", "person_id" ] }, "identifiers_i2": { "columns": [ "identifier", "type_id", "external_identity_id" ] }, "identifiers_i3": { "columns": [ "type_id" ] }, - "identifiers_i4": { "needed": false, "columns": [ "provisioning_target_id" ] } + "identifiers_i4": { "needed": false, "columns": [ "provisioning_target_id" ] }, + "identifiers_i5": { "columns": [ "lower(identifier)", "type_id" ] } }, "mvea": [ "person", "external_identity", "group" ], "sourced": true diff --git a/app/src/Lib/Util/SchemaManager.php b/app/src/Lib/Util/SchemaManager.php index 1819ecf86..ef3686850 100644 --- a/app/src/Lib/Util/SchemaManager.php +++ b/app/src/Lib/Util/SchemaManager.php @@ -261,12 +261,31 @@ protected function processSchema( // $flags and $options as passed to Index(), but otherwise undocumented $flags = []; $options = []; + + // XXX DBAL does not support expression indexes. We will trick DBAL by + // temporary adding the virtual column in the table. This will make + // no difference to the table end result since the actual query list + // will be executed later. What we actually do is treat the expression + // as a temporary virtual column + // https://www.postgresql.org/docs/14/indexes-expressional.html + $tempColumns = []; + foreach ($iCfg->columns as $clm_name) { + if (! $table->hasColumn($clm_name)) { + $table->addColumn($clm_name, "string"); + $tempColumns[] = $clm_name; + } + } if(isset($iCfg->unique) && $iCfg->unique) { $table->addUniqueConstraint($iCfg->columns, $iName, $flags, $options); } else { $table->addIndex($iCfg->columns, $iName, $flags, $options); } + + foreach ($tempColumns as $clm_name) { + $table->dropColumn($clm_name); + } + $tempColumns = []; } }