Skip to content

Commit

Permalink
indexing virtual fields with dbal
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Igoumenos committed Oct 14, 2023
1 parent 67f9fed commit 5c0deab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions app/src/Lib/Util/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}
}

Expand Down

0 comments on commit 5c0deab

Please sign in to comment.