protected function SchemaMigrator::recreateIndexes in Schema 8
Parameters
$table TableComparison:
1 call to SchemaMigrator::recreateIndexes()
- SchemaMigrator::execute in src/
Migration/ SchemaMigrator.php
File
- src/
Migration/ SchemaMigrator.php, line 226 - Contains Drupal\schema\Migration\SchemaMigrator.
Class
- SchemaMigrator
- Modifies the database schema to match the declared schema.
Namespace
Drupal\schema\MigrationCode
protected function recreateIndexes($table) {
// Recreate indices by first removing all, then adding them one by one.
$existing = $this->dbschema
->getIndexes($table
->getTableName());
$count = 0;
foreach ($existing as $index) {
$this->dbschema
->dropIndex($table
->getTableName(), $index);
$this
->logSuccess("Dropped index {index} from {table}.", array(
'table' => $table
->getTableName(),
'index' => $index,
));
$count++;
}
if ($count > 0) {
$this
->logSuccess("Dropped {num} existing indexes from {table}.", array(
'table' => $table
->getTableName(),
'num' => $count,
));
}
$indexes = $table
->getDeclaredIndexes($this
->options()->recreateExtraIndexes);
foreach ($indexes['indexes'] as $i_name => $fields) {
$this->dbschema
->addIndex($table
->getTableName(), $i_name, $fields);
$this
->logSuccess("Added index {index} to {table} on {keys}.", array(
'table' => $table
->getTableName(),
'index' => $i_name,
'keys' => '[' . implode(', ', $fields) . ']',
));
}
foreach ($indexes['unique keys'] as $i_name => $fields) {
$this->dbschema
->addUniqueKey($table
->getTableName(), $i_name, $fields);
$this
->logSuccess("Added index {index} to {table} on {keys}.", array(
'table' => $table
->getTableName(),
'index' => $i_name,
'keys' => '[' . implode(', ', $fields) . ']',
));
}
}