From df44acfa070dfd44cc84d1986eb9b87e6ecfbc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 27 Nov 2020 13:24:33 +0100 Subject: [PATCH] Add missing index on oc_cards and rename if it previously existed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- core/Application.php | 4 ++++ core/Command/Db/AddMissingIndices.php | 33 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/core/Application.php b/core/Application.php index 4a4d2c6ef3..6aec7fd230 100644 --- a/core/Application.php +++ b/core/Application.php @@ -144,6 +144,10 @@ class Application extends App { if (!$table->hasIndex('cards_abid')) { $subject->addHintForMissingSubject($table->getName(), 'cards_abid'); } + + if (!$table->hasIndex('cards_abiduri')) { + $subject->addHintForMissingSubject($table->getName(), 'cards_abiduri'); + } } if ($schema->hasTable('cards_properties')) { diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php index c4d8f6d7e3..41ce626405 100644 --- a/core/Command/Db/AddMissingIndices.php +++ b/core/Command/Db/AddMissingIndices.php @@ -193,8 +193,23 @@ class AddMissingIndices extends Command { } $output->writeln('Check indices of the cards table.'); + $cardsUpdated = false; if ($schema->hasTable('cards')) { $table = $schema->getTable('cards'); + + if ($table->hasIndex('addressbookid_uri_index')) { + $output->writeln('Renaming addressbookid_uri_index index to to the cards table, this can take some time...'); + + foreach ($table->getIndexes() as $index) { + if ($index->getColumns() === ['addressbookid', 'uri']) { + $table->renameIndex('addressbookid_uri_index', 'cards_abiduri'); + } + } + + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $cardsUpdated = true; + } + if (!$table->hasIndex('cards_abid')) { $output->writeln('Adding cards_abid index to the cards table, this can take some time...'); @@ -206,6 +221,24 @@ class AddMissingIndices extends Command { $table->addIndex(['addressbookid'], 'cards_abid'); $this->connection->migrateToSchema($schema->getWrappedSchema()); + $cardsUpdated = true; + } + + if (!$table->hasIndex('cards_abiduri')) { + $output->writeln('Adding cards_abiduri index to the cards table, this can take some time...'); + + foreach ($table->getIndexes() as $index) { + if ($index->getColumns() === ['addressbookid', 'uri']) { + $table->dropIndex($index->getName()); + } + } + + $table->addIndex(['addressbookid', 'uri'], 'cards_abiduri'); + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $cardsUpdated = true; + } + + if ($cardsUpdated) { $updated = true; $output->writeln('cards table updated successfully.'); }