diff options
author | Joas Schilling <coding@schilljs.com> | 2019-03-27 11:42:33 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-03-27 13:32:59 +0100 |
commit | 274658629d2f7e72de123a8763f2578f79cb3376 (patch) | |
tree | 4af81fdbc7c3440f9657b24fe46037a23f741a46 /core | |
parent | 86594e8c18123db6696f4cedfc0578d036ad5dd6 (diff) | |
download | nextcloud-server-274658629d2f7e72de123a8763f2578f79cb3376.tar.gz nextcloud-server-274658629d2f7e72de123a8763f2578f79cb3376.zip |
Make sure all tables have named indexes
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/Application.php | 38 | ||||
-rw-r--r-- | core/Command/Db/AddMissingIndices.php | 81 | ||||
-rw-r--r-- | core/Migrations/Version14000Date20180626223656.php | 2 | ||||
-rw-r--r-- | core/Migrations/Version16000Date20190212081545.php | 6 |
4 files changed, 123 insertions, 4 deletions
diff --git a/core/Application.php b/core/Application.php index 94990df9356..1a7cf8aa10c 100644 --- a/core/Application.php +++ b/core/Application.php @@ -93,6 +93,44 @@ class Application extends App { $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid'); } } + + if ($schema->hasTable('login_flow_v2')) { + $table = $schema->getTable('login_flow_v2'); + + if (!$table->hasIndex('poll_token')) { + $subject->addHintForMissingSubject($table->getName(), 'poll_token'); + } + if (!$table->hasIndex('login_token')) { + $subject->addHintForMissingSubject($table->getName(), 'login_token'); + } + if (!$table->hasIndex('timestamp')) { + $subject->addHintForMissingSubject($table->getName(), 'timestamp'); + } + } + + if ($schema->hasTable('whats_new')) { + $table = $schema->getTable('whats_new'); + + if (!$table->hasIndex('version')) { + $subject->addHintForMissingSubject($table->getName(), 'version'); + } + } + + if ($schema->hasTable('cards')) { + $table = $schema->getTable('cards'); + + if (!$table->hasIndex('addressbookid')) { + $subject->addHintForMissingSubject($table->getName(), 'addressbookid'); + } + } + + if ($schema->hasTable('cards_properties')) { + $table = $schema->getTable('cards_properties'); + + if (!$table->hasIndex('addressbookid')) { + $subject->addHintForMissingSubject($table->getName(), 'addressbookid'); + } + } } ); } diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php index 3bc66988529..9df76f67b7b 100644 --- a/core/Command/Db/AddMissingIndices.php +++ b/core/Command/Db/AddMissingIndices.php @@ -140,6 +140,87 @@ class AddMissingIndices extends Command { } } + $output->writeln('<info>Check indices of the login_flow_v2 table.</info>'); + if ($schema->hasTable('login_flow_v2')) { + $table = $schema->getTable('login_flow_v2'); + if (!$table->hasIndex('poll_token')) { + $output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>'); + + foreach ($table->getIndexes() as $index) { + $columns = $index->getColumns(); + if ($columns === ['poll_token'] || + $columns === ['login_token'] || + $columns === ['timestamp']) { + $table->dropIndex($index->getName()); + } + } + + $table->addUniqueIndex(['poll_token'], 'poll_token'); + $table->addUniqueIndex(['login_token'], 'login_token'); + $table->addIndex(['timestamp'], 'timestamp'); + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $updated = true; + $output->writeln('<info>login_flow_v2 table updated successfully.</info>'); + } + } + + $output->writeln('<info>Check indices of the whats_new table.</info>'); + if ($schema->hasTable('whats_new')) { + $table = $schema->getTable('whats_new'); + if (!$table->hasIndex('version')) { + $output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>'); + + foreach ($table->getIndexes() as $index) { + if ($index->getColumns() === ['version']) { + $table->dropIndex($index->getName()); + } + } + + $table->addUniqueIndex(['version'], 'version'); + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $updated = true; + $output->writeln('<info>whats_new table updated successfully.</info>'); + } + } + + $output->writeln('<info>Check indices of the cards table.</info>'); + if ($schema->hasTable('cards')) { + $table = $schema->getTable('cards'); + if (!$table->hasIndex('addressbookid')) { + $output->writeln('<info>Adding addressbookid index to the cards table, this can take some time...</info>'); + + foreach ($table->getIndexes() as $index) { + if ($index->getColumns() === ['addressbookid']) { + $table->dropIndex($index->getName()); + } + } + + $table->addIndex(['addressbookid'], 'addressbookid'); + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $updated = true; + $output->writeln('<info>cards table updated successfully.</info>'); + } + } + + $output->writeln('<info>Check indices of the cards_properties table.</info>'); + if ($schema->hasTable('cards_properties')) { + $table = $schema->getTable('cards_properties'); + if (!$table->hasIndex('addressbookid')) { + $output->writeln('<info>Adding addressbookid index to the cards_properties table, this can take some time...</info>'); + + foreach ($table->getIndexes() as $index) { + if ($index->getColumns() === ['addressbookid']) { + $table->dropIndex($index->getName()); + } + } + + $table->addIndex(['addressbookid'], 'addressbookid'); + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $updated = true; + $output->writeln('<info>cards_properties table updated successfully.</info>'); + } + } + if (!$updated) { $output->writeln('<info>Done.</info>'); } diff --git a/core/Migrations/Version14000Date20180626223656.php b/core/Migrations/Version14000Date20180626223656.php index fb7a6c647bc..17b3674d272 100644 --- a/core/Migrations/Version14000Date20180626223656.php +++ b/core/Migrations/Version14000Date20180626223656.php @@ -60,7 +60,7 @@ class Version14000Date20180626223656 extends SimpleMigrationStep { 'default' => '', ]); $table->setPrimaryKey(['id']); - $table->addUniqueIndex(['version']); + $table->addUniqueIndex(['version'], 'version'); $table->addIndex(['version', 'etag'], 'version_etag_idx'); } diff --git a/core/Migrations/Version16000Date20190212081545.php b/core/Migrations/Version16000Date20190212081545.php index 6f6902bf177..dcb2722222a 100644 --- a/core/Migrations/Version16000Date20190212081545.php +++ b/core/Migrations/Version16000Date20190212081545.php @@ -92,9 +92,9 @@ class Version16000Date20190212081545 extends SimpleMigrationStep { 'length' => 1024, ]); $table->setPrimaryKey(['id']); - $table->addUniqueIndex(['poll_token']); - $table->addUniqueIndex(['login_token']); - $table->addIndex(['timestamp']); + $table->addUniqueIndex(['poll_token'], 'poll_token'); + $table->addUniqueIndex(['login_token'], 'login_token'); + $table->addIndex(['timestamp'], 'timestamp'); return $schema; } |