]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add missing index on oc_cards and rename if it previously existed
authorJulius Härtl <jus@bitgrid.net>
Fri, 27 Nov 2020 12:24:33 +0000 (13:24 +0100)
committerJulius Härtl <jus@bitgrid.net>
Mon, 14 Dec 2020 10:12:51 +0000 (11:12 +0100)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
core/Application.php
core/Command/Db/AddMissingIndices.php

index 4a4d2c6ef35c0fdcfd85b84d37ea958e922e45c0..6aec7fd2305f60a641c9990bfb848f4a486b19eb 100644 (file)
@@ -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')) {
index c4d8f6d7e310ad307f46dc6213fd7ce69960c22f..41ce626405e62b3a68ce26e5b684699ad387a9f1 100644 (file)
@@ -193,8 +193,23 @@ class AddMissingIndices extends Command {
                }
 
                $output->writeln('<info>Check indices of the cards table.</info>');
+               $cardsUpdated = false;
                if ($schema->hasTable('cards')) {
                        $table = $schema->getTable('cards');
+
+                       if ($table->hasIndex('addressbookid_uri_index')) {
+                               $output->writeln('<info>Renaming addressbookid_uri_index index to  to the cards table, this can take some time...</info>');
+
+                               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('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
 
@@ -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('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');
+
+                               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('<info>cards table updated successfully.</info>');
                        }