Skip to content

Commit

Permalink
Add missing index on oc_cards and rename if it previously existed
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Dec 9, 2020
1 parent 3c9218a commit c77e259
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ function (GenericEvent $event) use ($container) {
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')) {
Expand Down
33 changes: 33 additions & 0 deletions core/Command/Db/AddMissingIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,23 @@ private function addCoreIndexes(OutputInterface $output) {
}

$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>');

Expand All @@ -213,6 +228,24 @@ private function addCoreIndexes(OutputInterface $output) {

$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>');
}
Expand Down

0 comments on commit c77e259

Please sign in to comment.