Skip to content

Commit 7dc212c

Browse files
authored
Merge pull request #4255 from nextcloud/fix/remove-obsolete-index
Fix/remove-obsolete-index
2 parents ff636fa + ac476d8 commit 7dc212c

3 files changed

Lines changed: 24 additions & 3 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
*

lib/Migration/V3/TableSchema.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ abstract class TableSchema {
6767
'polls_polls_deleted' => ['columns' => ['deleted']],
6868
'polls_polls_owners' => ['columns' => ['owner']],
6969
],
70-
PollGroup::RELATION_TABLE => [
71-
'polls_groups_polls' => ['columns' => ['poll_id', 'group_id']],
72-
],
7370
Option::TABLE => [
7471
'polls_options' => ['columns' => ['poll_id', 'deleted']],
7572
'polls_options_hash' => ['columns' => ['poll_id', 'poll_option_hash', 'deleted']],

0 commit comments

Comments
 (0)