protected function getIndexes()
{
foreach ($this->commonTables as $table => $currentSchema) {
$currentIndexes = $currentSchema->indexes();
$oldIndexes = $this->dumpSchema[$table]->indexes();
sort($currentIndexes);
sort($oldIndexes);
// brand new indexes
$addedIndexes = array_diff($currentIndexes, $oldIndexes);
foreach ($addedIndexes as $indexName) {
$this->templateData[$table]['indexes']['add'][$indexName] = $currentSchema->index($indexName);
}
// indexes having the same name between new and old schema
// if present in both, check if they are the same : if not, remove the old one and add the new one
foreach ($currentIndexes as $indexName) {
$index = $currentSchema->index($indexName);
if (in_array($indexName, $oldIndexes) && $index !== $this->dumpSchema[$table]->index($indexName)) {
$this->templateData[$table]['indexes']['remove'][$indexName] = $this->dumpSchema[$table]->index($indexName);
$this->templateData[$table]['indexes']['add'][$indexName] = $index;
}
}
// indexes deletion
if (!isset($this->templateData[$table]['indexes']['remove'])) {
$this->templateData[$table]['indexes']['remove'] = [];
}
$removedIndexes = array_diff($oldIndexes, $currentIndexes);
$parts = [];
if (!empty($removedIndexes)) {
foreach ($removedIndexes as $index) {
$parts[$index] = $this->dumpSchema[$table]->index($index);
}
}
$this->templateData[$table]['indexes']['remove'] = array_merge($this->templateData[$table]['indexes']['remove'], $parts);
}
}