Make sure all tables have named indexes

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-03-27 11:42:33 +01:00 committed by Roeland Jago Douma
parent 86594e8c18
commit 274658629d
No known key found for this signature in database
GPG Key ID: F941078878347C0C
5 changed files with 125 additions and 6 deletions

View File

@ -40,10 +40,10 @@ class Version1004Date20170924124212 extends SimpleMigrationStep {
$schema = $schemaClosure();
$table = $schema->getTable('cards');
$table->addIndex(['addressbookid']);
$table->addIndex(['addressbookid'], 'addressbookid');
$table = $schema->getTable('cards_properties');
$table->addIndex(['addressbookid']);
$table->addIndex(['addressbookid'], 'addressbookid');
return $schema;
}

View File

@ -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');
}
}
}
);
}

View File

@ -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>');
}

View File

@ -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');
}

View File

@ -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;
}