Skip to content

Commit ac476d8

Browse files
committed
list index after index creation command
Signed-off-by: dartcafe <github@dartcafe.de>
1 parent a68c692 commit ac476d8

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

lib/Command/Db/CreateIndices.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ protected function runCommands(): int {
4040
$this->addForeignKeyConstraints();
4141
$this->addUniqueIndices();
4242
$this->connection->migrateToSchema($this->schema);
43+
$this->listExistingIndices();
4344

4445
return 0;
4546
}
4647

48+
private function listExistingIndices(): void {
49+
$this->printComment('Existing indices:');
50+
$messages = $this->indexManager->listExistingIndices();
51+
$this->printInfo($messages, ' - ');
52+
}
4753
/**
4854
* add an on delete fk contraint to all tables referencing the main polls table
4955
*/

lib/Db/V3/IndexManager.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ public function createForeignKeyConstraint(string $parentTableName, string $chil
104104
return 'Added ' . $parentTableName . '[' . $constraintColumn . '] <- ' . $childTableName . '[id]';
105105
}
106106

107+
public function listExistingIndices() {
108+
$this->needsSchema();
109+
$messages = [];
110+
111+
foreach (array_keys(TableSchema::TABLES) as $tableName) {
112+
$tableName = $this->getTableName($tableName);
113+
114+
if ($this->schema->hasTable($tableName)) {
115+
$table = $this->schema->getTable($tableName);
116+
117+
foreach ($table->getIndexes() as $index) {
118+
$messages[] = $tableName . ' - ' . $index->getName() . ' (' . implode(',', $index->getColumns()) . ')';
119+
}
120+
}
121+
}
122+
return $messages;
123+
}
124+
107125
/**
108126
* Create one named index for table
109127
*

0 commit comments

Comments
 (0)