aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Db
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/Db')
-rw-r--r--core/Command/Db/AddMissingColumns.php68
-rw-r--r--core/Command/Db/AddMissingIndices.php439
-rw-r--r--core/Command/Db/AddMissingPrimaryKeys.php151
-rw-r--r--core/Command/Db/ConvertFilecacheBigInt.php18
-rw-r--r--core/Command/Db/ConvertMysqlToMB4.php17
-rw-r--r--core/Command/Db/ConvertType.php15
-rw-r--r--core/Command/Db/Migrations/ExecuteCommand.php11
-rw-r--r--core/Command/Db/Migrations/GenerateCommand.php14
-rw-r--r--core/Command/Db/Migrations/MigrateCommand.php7
-rw-r--r--core/Command/Db/Migrations/StatusCommand.php7
10 files changed, 163 insertions, 584 deletions
diff --git a/core/Command/Db/AddMissingColumns.php b/core/Command/Db/AddMissingColumns.php
index acc05c3b7ff..07763c66154 100644
--- a/core/Command/Db/AddMissingColumns.php
+++ b/core/Command/Db/AddMissingColumns.php
@@ -28,13 +28,12 @@ namespace OC\Core\Command\Db;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
-use OCP\IDBConnection;
+use OCP\DB\Events\AddMissingColumnsEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class AddMissingColumns
@@ -45,14 +44,11 @@ use Symfony\Component\EventDispatcher\GenericEvent;
* @package OC\Core\Command\Db
*/
class AddMissingColumns extends Command {
- private Connection $connection;
- private EventDispatcherInterface $dispatcher;
-
- public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
+ public function __construct(
+ private Connection $connection,
+ private IEventDispatcher $dispatcher,
+ ) {
parent::__construct();
-
- $this->connection = $connection;
- $this->dispatcher = $dispatcher;
}
protected function configure() {
@@ -63,46 +59,38 @@ class AddMissingColumns extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $this->addCoreColumns($output, $input->getOption('dry-run'));
+ $dryRun = $input->getOption('dry-run');
// Dispatch event so apps can also update columns if needed
- $event = new GenericEvent($output);
- $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_COLUMNS_EVENT, $event);
- return 0;
- }
-
- /**
- * add missing indices to the share table
- *
- * @param OutputInterface $output
- * @param bool $dryRun If true, will return the sql queries instead of running them.
- * @throws \Doctrine\DBAL\Schema\SchemaException
- */
- private function addCoreColumns(OutputInterface $output, bool $dryRun): void {
- $output->writeln('<info>Check columns of the comments table.</info>');
-
- $schema = new SchemaWrapper($this->connection);
+ $event = new AddMissingColumnsEvent();
+ $this->dispatcher->dispatchTyped($event);
+ $missingColumns = $event->getMissingColumns();
$updated = false;
- if ($schema->hasTable('comments')) {
- $table = $schema->getTable('comments');
- if (!$table->hasColumn('reference_id')) {
- $output->writeln('<info>Adding additional reference_id column to the comments table, this can take some time...</info>');
- $table->addColumn('reference_id', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
+ if (!empty($missingColumns)) {
+ $schema = new SchemaWrapper($this->connection);
+
+ foreach ($missingColumns as $missingColumn) {
+ if ($schema->hasTable($missingColumn['tableName'])) {
+ $table = $schema->getTable($missingColumn['tableName']);
+ if (!$table->hasColumn($missingColumn['columnName'])) {
+ $output->writeln('<info>Adding additional ' . $missingColumn['columnName'] . ' column to the ' . $missingColumn['tableName'] . ' table, this can take some time...</info>');
+ $table->addColumn($missingColumn['columnName'], $missingColumn['typeName'], $missingColumn['options']);
+ $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
+ if ($dryRun && $sqlQueries !== null) {
+ $output->writeln($sqlQueries);
+ }
+ $updated = true;
+ $output->writeln('<info>' . $missingColumn['tableName'] . ' table updated successfully.</info>');
+ }
}
- $updated = true;
- $output->writeln('<info>Comments table updated successfully.</info>');
}
}
if (!$updated) {
$output->writeln('<info>Done.</info>');
}
+
+ return 0;
}
}
diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php
index 5799a462ffa..1e10b6152ce 100644
--- a/core/Command/Db/AddMissingIndices.php
+++ b/core/Command/Db/AddMissingIndices.php
@@ -33,16 +33,14 @@ declare(strict_types=1);
*/
namespace OC\Core\Command\Db;
-use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
-use OCP\IDBConnection;
+use OCP\DB\Events\AddMissingIndicesEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class AddMissingIndices
@@ -53,14 +51,11 @@ use Symfony\Component\EventDispatcher\GenericEvent;
* @package OC\Core\Command\Db
*/
class AddMissingIndices extends Command {
- private Connection $connection;
- private EventDispatcherInterface $dispatcher;
-
- public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
+ public function __construct(
+ private Connection $connection,
+ private IEventDispatcher $dispatcher,
+ ) {
parent::__construct();
-
- $this->connection = $connection;
- $this->dispatcher = $dispatcher;
}
protected function configure() {
@@ -71,394 +66,94 @@ class AddMissingIndices extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $this->addCoreIndexes($output, $input->getOption('dry-run'));
+ $dryRun = $input->getOption('dry-run');
// Dispatch event so apps can also update indexes if needed
- $event = new GenericEvent($output);
- $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
- return 0;
- }
-
- /**
- * add missing indices to the share table
- *
- * @param OutputInterface $output
- * @param bool $dryRun If true, will return the sql queries instead of running them.
- * @throws \Doctrine\DBAL\Schema\SchemaException
- */
- private function addCoreIndexes(OutputInterface $output, bool $dryRun): void {
- $output->writeln('<info>Check indices of the share table.</info>');
-
- $schema = new SchemaWrapper($this->connection);
- $updated = false;
-
- if ($schema->hasTable('share')) {
- $table = $schema->getTable('share');
- if (!$table->hasIndex('share_with_index')) {
- $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>');
- $table->addIndex(['share_with'], 'share_with_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Share table updated successfully.</info>');
- }
-
- if (!$table->hasIndex('parent_index')) {
- $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>');
- $table->addIndex(['parent'], 'parent_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Share table updated successfully.</info>');
- }
-
- if (!$table->hasIndex('owner_index')) {
- $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>');
- $table->addIndex(['uid_owner'], 'owner_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Share table updated successfully.</info>');
- }
-
- if (!$table->hasIndex('initiator_index')) {
- $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>');
- $table->addIndex(['uid_initiator'], 'initiator_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Share table updated successfully.</info>');
- }
- }
-
- $output->writeln('<info>Check indices of the filecache table.</info>');
- if ($schema->hasTable('filecache')) {
- $table = $schema->getTable('filecache');
- if (!$table->hasIndex('fs_mtime')) {
- $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>');
- $table->addIndex(['mtime'], 'fs_mtime');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Filecache table updated successfully.</info>');
- }
- if (!$table->hasIndex('fs_size')) {
- $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
- $table->addIndex(['size'], 'fs_size');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Filecache table updated successfully.</info>');
- }
- if (!$table->hasIndex('fs_id_storage_size')) {
- $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
- $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Filecache table updated successfully.</info>');
- }
- if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
- $output->writeln('<info>Adding additional path index to the filecache table, this can take some time...</info>');
- $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Filecache table updated successfully.</info>');
- }
- }
-
- $output->writeln('<info>Check indices of the twofactor_providers table.</info>');
- if ($schema->hasTable('twofactor_providers')) {
- $table = $schema->getTable('twofactor_providers');
- if (!$table->hasIndex('twofactor_providers_uid')) {
- $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>');
- $table->addIndex(['uid'], 'twofactor_providers_uid');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>Twofactor_providers table updated successfully.</info>');
- }
- }
-
- $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');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>login_flow_v2 table updated successfully.</info>');
- }
- }
+ $event = new AddMissingIndicesEvent();
+ $this->dispatcher->dispatchTyped($event);
+
+ $missingIndices = $event->getMissingIndices();
+ $toReplaceIndices = $event->getIndicesToReplace();
+
+ if ($missingIndices !== [] || $toReplaceIndices !== []) {
+ $schema = new SchemaWrapper($this->connection);
+
+ foreach ($missingIndices as $missingIndex) {
+ if ($schema->hasTable($missingIndex['tableName'])) {
+ $table = $schema->getTable($missingIndex['tableName']);
+ if (!$table->hasIndex($missingIndex['indexName'])) {
+ $output->writeln('<info>Adding additional ' . $missingIndex['indexName'] . ' index to the ' . $table->getName() . ' table, this can take some time...</info>');
+
+ if ($missingIndex['dropUnnamedIndex']) {
+ foreach ($table->getIndexes() as $index) {
+ $columns = $index->getColumns();
+ if ($columns === $missingIndex['columns']) {
+ $table->dropIndex($index->getName());
+ }
+ }
+ }
- $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>');
+ if ($missingIndex['uniqueIndex']) {
+ $table->addUniqueIndex($missingIndex['columns'], $missingIndex['indexName'], $missingIndex['options']);
+ } else {
+ $table->addIndex($missingIndex['columns'], $missingIndex['indexName'], [], $missingIndex['options']);
+ }
- foreach ($table->getIndexes() as $index) {
- if ($index->getColumns() === ['version']) {
- $table->dropIndex($index->getName());
+ if (!$dryRun) {
+ $this->connection->migrateToSchema($schema->getWrappedSchema());
+ }
+ $output->writeln('<info>' . $table->getName() . ' table updated successfully.</info>');
}
}
-
- $table->addUniqueIndex(['version'], 'version');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>whats_new table updated successfully.</info>');
}
- }
-
- $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')) {
- if ($table->hasIndex('cards_abiduri')) {
- $table->dropIndex('addressbookid_uri_index');
- } else {
- $output->writeln('<info>Renaming addressbookid_uri_index index to cards_abiduri in the cards table, this can take some time...</info>');
+ foreach ($toReplaceIndices as $toReplaceIndex) {
+ if ($schema->hasTable($toReplaceIndex['tableName'])) {
+ $table = $schema->getTable($toReplaceIndex['tableName']);
- foreach ($table->getIndexes() as $index) {
- if ($index->getColumns() === ['addressbookid', 'uri']) {
- $table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
+ $allOldIndicesExists = true;
+ foreach ($toReplaceIndex['oldIndexNames'] as $oldIndexName) {
+ if (!$table->hasIndex($oldIndexName)) {
+ $allOldIndicesExists = false;
}
}
- }
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $cardsUpdated = true;
- }
-
- if (!$table->hasIndex('cards_abid')) {
- $output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
-
- foreach ($table->getIndexes() as $index) {
- if ($index->getColumns() === ['addressbookid']) {
- $table->dropIndex($index->getName());
+ if (!$allOldIndicesExists) {
+ continue;
}
- }
- $table->addIndex(['addressbookid'], 'cards_abid');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $cardsUpdated = true;
- }
+ $output->writeln('<info>Adding additional ' . $toReplaceIndex['newIndexName'] . ' index to the ' . $table->getName() . ' table, this can take some time...</info>');
- 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());
+ if ($toReplaceIndex['uniqueIndex']) {
+ $table->addUniqueIndex($toReplaceIndex['columns'], $toReplaceIndex['newIndexName'], $toReplaceIndex['options']);
+ } else {
+ $table->addIndex($toReplaceIndex['columns'], $toReplaceIndex['newIndexName'], [], $toReplaceIndex['options']);
}
- }
- $table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $cardsUpdated = true;
- }
-
- if ($cardsUpdated) {
- $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('cards_prop_abid')) {
- $output->writeln('<info>Adding cards_prop_abid 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());
+ if (!$dryRun) {
+ $this->connection->migrateToSchema($schema->getWrappedSchema());
}
- }
-
- $table->addIndex(['addressbookid'], 'cards_prop_abid');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>cards_properties table updated successfully.</info>');
- }
- }
- $output->writeln('<info>Check indices of the calendarobjects_props table.</info>');
- if ($schema->hasTable('calendarobjects_props')) {
- $table = $schema->getTable('calendarobjects_props');
- if (!$table->hasIndex('calendarobject_calid_index')) {
- $output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>');
-
- $table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>calendarobjects_props table updated successfully.</info>');
- }
- }
-
- $output->writeln('<info>Check indices of the schedulingobjects table.</info>');
- if ($schema->hasTable('schedulingobjects')) {
- $table = $schema->getTable('schedulingobjects');
- if (!$table->hasIndex('schedulobj_principuri_index')) {
- $output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>');
-
- $table->addIndex(['principaluri'], 'schedulobj_principuri_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>schedulingobjects table updated successfully.</info>');
- }
- }
-
- $output->writeln('<info>Check indices of the oc_properties table.</info>');
- if ($schema->hasTable('properties')) {
- $table = $schema->getTable('properties');
- $propertiesUpdated = false;
-
- if (!$table->hasIndex('properties_path_index')) {
- $output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>');
-
- $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $propertiesUpdated = true;
- }
- if (!$table->hasIndex('properties_pathonly_index')) {
- $output->writeln('<info>Adding properties_pathonly_index index to the oc_properties table, this can take some time...</info>');
-
- $table->addIndex(['propertypath'], 'properties_pathonly_index');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $propertiesUpdated = true;
- }
-
- if ($propertiesUpdated) {
- $updated = true;
- $output->writeln('<info>oc_properties table updated successfully.</info>');
- }
- }
-
- $output->writeln('<info>Check indices of the oc_jobs table.</info>');
- if ($schema->hasTable('jobs')) {
- $table = $schema->getTable('jobs');
- if (!$table->hasIndex('job_lastcheck_reserved')) {
- $output->writeln('<info>Adding job_lastcheck_reserved index to the oc_jobs table, this can take some time...</info>');
+ foreach ($toReplaceIndex['oldIndexNames'] as $oldIndexName) {
+ $output->writeln('<info>Removing ' . $oldIndexName . ' index from the ' . $table->getName() . ' table</info>');
+ $table->dropIndex($oldIndexName);
+ }
- $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
+ if (!$dryRun) {
+ $this->connection->migrateToSchema($schema->getWrappedSchema());
+ }
+ $output->writeln('<info>' . $table->getName() . ' table updated successfully.</info>');
}
- $updated = true;
- $output->writeln('<info>oc_properties table updated successfully.</info>');
}
- }
- $output->writeln('<info>Check indices of the oc_direct_edit table.</info>');
- if ($schema->hasTable('direct_edit')) {
- $table = $schema->getTable('direct_edit');
- if (!$table->hasIndex('direct_edit_timestamp')) {
- $output->writeln('<info>Adding direct_edit_timestamp index to the oc_direct_edit table, this can take some time...</info>');
-
- $table->addIndex(['timestamp'], 'direct_edit_timestamp');
+ if ($dryRun) {
$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
+ if ($sqlQueries !== null) {
$output->writeln($sqlQueries);
}
- $updated = true;
- $output->writeln('<info>oc_direct_edit table updated successfully.</info>');
- }
- }
-
- $output->writeln('<info>Check indices of the oc_preferences table.</info>');
- if ($schema->hasTable('preferences')) {
- $table = $schema->getTable('preferences');
- if (!$table->hasIndex('preferences_app_key')) {
- $output->writeln('<info>Adding preferences_app_key index to the oc_preferences table, this can take some time...</info>');
-
- $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
- $this->connection->migrateToSchema($schema->getWrappedSchema());
- $updated = true;
- $output->writeln('<info>oc_properties table updated successfully.</info>');
}
}
- $output->writeln('<info>Check indices of the oc_mounts table.</info>');
- if ($schema->hasTable('mounts')) {
- $table = $schema->getTable('mounts');
- if (!$table->hasIndex('mounts_class_index')) {
- $output->writeln('<info>Adding mounts_class_index index to the oc_mounts table, this can take some time...</info>');
-
- $table->addIndex(['mount_provider_class'], 'mounts_class_index');
- $this->connection->migrateToSchema($schema->getWrappedSchema());
- $updated = true;
- $output->writeln('<info>oc_mounts table updated successfully.</info>');
- }
- }
-
- if (!$updated) {
- $output->writeln('<info>Done.</info>');
- }
+ return 0;
}
}
diff --git a/core/Command/Db/AddMissingPrimaryKeys.php b/core/Command/Db/AddMissingPrimaryKeys.php
index 8262cf37e77..658eb0b0f5a 100644
--- a/core/Command/Db/AddMissingPrimaryKeys.php
+++ b/core/Command/Db/AddMissingPrimaryKeys.php
@@ -28,13 +28,12 @@ namespace OC\Core\Command\Db;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
-use OCP\IDBConnection;
+use OCP\DB\Events\AddMissingPrimaryKeyEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class AddMissingPrimaryKeys
@@ -45,14 +44,11 @@ use Symfony\Component\EventDispatcher\GenericEvent;
* @package OC\Core\Command\Db
*/
class AddMissingPrimaryKeys extends Command {
- private Connection $connection;
- private EventDispatcherInterface $dispatcher;
-
- public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
+ public function __construct(
+ private Connection $connection,
+ private IEventDispatcher $dispatcher,
+ ) {
parent::__construct();
-
- $this->connection = $connection;
- $this->dispatcher = $dispatcher;
}
protected function configure() {
@@ -63,131 +59,44 @@ class AddMissingPrimaryKeys extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $this->addCorePrimaryKeys($output, $input->getOption('dry-run'));
+ $dryRun = $input->getOption('dry-run');
// Dispatch event so apps can also update indexes if needed
- $event = new GenericEvent($output);
- $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_PRIMARY_KEYS_EVENT, $event);
- return 0;
- }
-
- /**
- * add missing indices to the share table
- *
- * @param OutputInterface $output
- * @param bool $dryRun If true, will return the sql queries instead of running them.
- * @throws \Doctrine\DBAL\Schema\SchemaException
- */
- private function addCorePrimaryKeys(OutputInterface $output, bool $dryRun): void {
- $output->writeln('<info>Check primary keys.</info>');
-
- $schema = new SchemaWrapper($this->connection);
+ $event = new AddMissingPrimaryKeyEvent();
+ $this->dispatcher->dispatchTyped($event);
+ $missingKeys = $event->getMissingPrimaryKeys();
$updated = false;
- if ($schema->hasTable('federated_reshares')) {
- $table = $schema->getTable('federated_reshares');
- if (!$table->hasPrimaryKey()) {
- $output->writeln('<info>Adding primary key to the federated_reshares table, this can take some time...</info>');
- $table->setPrimaryKey(['share_id'], 'federated_res_pk');
- if ($table->hasIndex('share_id_index')) {
- $table->dropIndex('share_id_index');
- }
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>federated_reshares table updated successfully.</info>');
- }
- }
-
- if ($schema->hasTable('systemtag_object_mapping')) {
- $table = $schema->getTable('systemtag_object_mapping');
- if (!$table->hasPrimaryKey()) {
- $output->writeln('<info>Adding primary key to the systemtag_object_mapping table, this can take some time...</info>');
- $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
- if ($table->hasIndex('mapping')) {
- $table->dropIndex('mapping');
- }
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>systemtag_object_mapping table updated successfully.</info>');
- }
- }
+ if (!empty($missingKeys)) {
+ $schema = new SchemaWrapper($this->connection);
- if ($schema->hasTable('comments_read_markers')) {
- $table = $schema->getTable('comments_read_markers');
- if (!$table->hasPrimaryKey()) {
- $output->writeln('<info>Adding primary key to the comments_read_markers table, this can take some time...</info>');
- $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
- if ($table->hasIndex('comments_marker_index')) {
- $table->dropIndex('comments_marker_index');
- }
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>comments_read_markers table updated successfully.</info>');
- }
- }
+ foreach ($missingKeys as $missingKey) {
+ if ($schema->hasTable($missingKey['tableName'])) {
+ $table = $schema->getTable($missingKey['tableName']);
+ if (!$table->hasPrimaryKey()) {
+ $output->writeln('<info>Adding primary key to the ' . $missingKey['tableName'] . ' table, this can take some time...</info>');
+ $table->setPrimaryKey($missingKey['columns'], $missingKey['primaryKeyName']);
- if ($schema->hasTable('collres_resources')) {
- $table = $schema->getTable('collres_resources');
- if (!$table->hasPrimaryKey()) {
- $output->writeln('<info>Adding primary key to the collres_resources table, this can take some time...</info>');
- $table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk');
- if ($table->hasIndex('collres_unique_res')) {
- $table->dropIndex('collres_unique_res');
- }
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>collres_resources table updated successfully.</info>');
- }
- }
+ if ($missingKey['formerIndex'] && $table->hasIndex($missingKey['formerIndex'])) {
+ $table->dropIndex($missingKey['formerIndex']);
+ }
- if ($schema->hasTable('collres_accesscache')) {
- $table = $schema->getTable('collres_accesscache');
- if (!$table->hasPrimaryKey()) {
- $output->writeln('<info>Adding primary key to the collres_accesscache table, this can take some time...</info>');
- $table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk');
- if ($table->hasIndex('collres_unique_user')) {
- $table->dropIndex('collres_unique_user');
- }
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>collres_accesscache table updated successfully.</info>');
- }
- }
+ $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
+ if ($dryRun && $sqlQueries !== null) {
+ $output->writeln($sqlQueries);
+ }
- if ($schema->hasTable('filecache_extended')) {
- $table = $schema->getTable('filecache_extended');
- if (!$table->hasPrimaryKey()) {
- $output->writeln('<info>Adding primary key to the filecache_extended table, this can take some time...</info>');
- $table->setPrimaryKey(['fileid'], 'fce_pk');
- if ($table->hasIndex('fce_fileid_idx')) {
- $table->dropIndex('fce_fileid_idx');
+ $updated = true;
+ $output->writeln('<info>' . $missingKey['tableName'] . ' table updated successfully.</info>');
+ }
}
- $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
- if ($dryRun && $sqlQueries !== null) {
- $output->writeln($sqlQueries);
- }
- $updated = true;
- $output->writeln('<info>filecache_extended table updated successfully.</info>');
}
}
if (!$updated) {
$output->writeln('<info>Done.</info>');
}
+
+ return 0;
}
}
diff --git a/core/Command/Db/ConvertFilecacheBigInt.php b/core/Command/Db/ConvertFilecacheBigInt.php
index f12ae15f0b3..44cd81cd7eb 100644
--- a/core/Command/Db/ConvertFilecacheBigInt.php
+++ b/core/Command/Db/ConvertFilecacheBigInt.php
@@ -33,19 +33,18 @@ namespace OC\Core\Command\Db;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Type;
-use OCP\DB\Types;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
+use OCP\DB\Types;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class ConvertFilecacheBigInt extends Command {
- private Connection $connection;
-
- public function __construct(Connection $connection) {
- $this->connection = $connection;
+ public function __construct(
+ private Connection $connection,
+ ) {
parent::__construct();
}
@@ -55,8 +54,10 @@ class ConvertFilecacheBigInt extends Command {
->setDescription('Convert the ID columns of the filecache to BigInt');
}
- protected function getColumnsByTable() {
- // also update in CheckSetupController::hasBigIntConversionPendingColumns()
+ /**
+ * @return array<string,string[]>
+ */
+ public static function getColumnsByTable(): array {
return [
'activity' => ['activity_id', 'object_id'],
'activity_mq' => ['mail_id'],
@@ -67,6 +68,7 @@ class ConvertFilecacheBigInt extends Command {
'filecache_extended' => ['fileid'],
'files_trash' => ['auto_id'],
'file_locks' => ['id'],
+ 'file_metadata' => ['id'],
'jobs' => ['id'],
'mimetypes' => ['id'],
'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'],
@@ -80,7 +82,7 @@ class ConvertFilecacheBigInt extends Command {
$isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
$updates = [];
- $tables = $this->getColumnsByTable();
+ $tables = static::getColumnsByTable();
foreach ($tables as $tableName => $columns) {
if (!$schema->hasTable($tableName)) {
continue;
diff --git a/core/Command/Db/ConvertMysqlToMB4.php b/core/Command/Db/ConvertMysqlToMB4.php
index 19a9532d910..a66fb46fc51 100644
--- a/core/Command/Db/ConvertMysqlToMB4.php
+++ b/core/Command/Db/ConvertMysqlToMB4.php
@@ -37,21 +37,12 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ConvertMysqlToMB4 extends Command {
- private IConfig $config;
- private IDBConnection $connection;
- private IURLGenerator $urlGenerator;
- private LoggerInterface $logger;
-
public function __construct(
- IConfig $config,
- IDBConnection $connection,
- IURLGenerator $urlGenerator,
- LoggerInterface $logger
+ private IConfig $config,
+ private IDBConnection $connection,
+ private IURLGenerator $urlGenerator,
+ private LoggerInterface $logger,
) {
- $this->config = $config;
- $this->connection = $connection;
- $this->urlGenerator = $urlGenerator;
- $this->logger = $logger;
parent::__construct();
}
diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php
index f7638e3024f..db618e938c0 100644
--- a/core/Command/Db/ConvertType.php
+++ b/core/Command/Db/ConvertType.php
@@ -35,11 +35,11 @@ namespace OC\Core\Command\Db;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\Table;
-use OCP\DB\Types;
use OC\DB\Connection;
use OC\DB\ConnectionFactory;
use OC\DB\MigrationService;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\DB\Types;
use OCP\IConfig;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
@@ -56,13 +56,12 @@ use function preg_match;
use function preg_quote;
class ConvertType extends Command implements CompletionAwareInterface {
- protected IConfig $config;
- protected ConnectionFactory $connectionFactory;
- protected array $columnTypes;
+ protected array $columnTypes = [];
- public function __construct(IConfig $config, ConnectionFactory $connectionFactory) {
- $this->config = $config;
- $this->connectionFactory = $connectionFactory;
+ public function __construct(
+ protected IConfig $config,
+ protected ConnectionFactory $connectionFactory,
+ ) {
parent::__construct();
}
@@ -200,7 +199,7 @@ class ConvertType extends Command implements CompletionAwareInterface {
$output->writeln('<comment>The following tables will not be converted:</comment>');
$output->writeln($extraFromTables);
if (!$input->getOption('all-apps')) {
- $output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>');
+ $output->writeln('<comment>Please note that tables belonging to disabled (but not removed) apps</comment>');
$output->writeln('<comment>can be included by specifying the --all-apps option.</comment>');
}
diff --git a/core/Command/Db/Migrations/ExecuteCommand.php b/core/Command/Db/Migrations/ExecuteCommand.php
index e87e133fa31..c75b575ab6c 100644
--- a/core/Command/Db/Migrations/ExecuteCommand.php
+++ b/core/Command/Db/Migrations/ExecuteCommand.php
@@ -35,13 +35,10 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExecuteCommand extends Command implements CompletionAwareInterface {
- private Connection $connection;
- private IConfig $config;
-
- public function __construct(Connection $connection, IConfig $config) {
- $this->connection = $connection;
- $this->config = $config;
-
+ public function __construct(
+ private Connection $connection,
+ private IConfig $config,
+ ) {
parent::__construct();
}
diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php
index 6c11c7705d2..47f65b5a11b 100644
--- a/core/Command/Db/Migrations/GenerateCommand.php
+++ b/core/Command/Db/Migrations/GenerateCommand.php
@@ -45,9 +45,9 @@ class GenerateCommand extends Command implements CompletionAwareInterface {
declare(strict_types=1);
/**
- * @copyright Copyright (c) {{year}} Your name <your@email.com>
+ * @copyright Copyright (c) {{year}} FIXME Your name <your@email.com>
*
- * @author Your name <your@email.com>
+ * FIXME @author Your name <your@email.com>
*
* @license GNU AGPL version 3 or any later version
*
@@ -74,13 +74,13 @@ use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
- * Auto-generated migration step: Please modify to your needs!
+ * FIXME Auto-generated migration step: Please modify to your needs!
*/
class {{classname}} extends SimpleMigrationStep {
/**
* @param IOutput $output
- * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
@@ -88,7 +88,7 @@ class {{classname}} extends SimpleMigrationStep {
/**
* @param IOutput $output
- * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
@@ -98,7 +98,7 @@ class {{classname}} extends SimpleMigrationStep {
/**
* @param IOutput $output
- * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
@@ -235,7 +235,7 @@ class {{classname}} extends SimpleMigrationStep {
$path = $dir . '/' . $className . '.php';
if (file_put_contents($path, $code) === false) {
- throw new RuntimeException('Failed to generate new migration step.');
+ throw new RuntimeException('Failed to generate new migration step. Could not write to ' . $path);
}
return $path;
diff --git a/core/Command/Db/Migrations/MigrateCommand.php b/core/Command/Db/Migrations/MigrateCommand.php
index f0f35716997..3e11b32665a 100644
--- a/core/Command/Db/Migrations/MigrateCommand.php
+++ b/core/Command/Db/Migrations/MigrateCommand.php
@@ -33,10 +33,9 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MigrateCommand extends Command implements CompletionAwareInterface {
- private Connection $connection;
-
- public function __construct(Connection $connection) {
- $this->connection = $connection;
+ public function __construct(
+ private Connection $connection,
+ ) {
parent::__construct();
}
diff --git a/core/Command/Db/Migrations/StatusCommand.php b/core/Command/Db/Migrations/StatusCommand.php
index 725ee075215..52bc51a169f 100644
--- a/core/Command/Db/Migrations/StatusCommand.php
+++ b/core/Command/Db/Migrations/StatusCommand.php
@@ -34,10 +34,9 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class StatusCommand extends Command implements CompletionAwareInterface {
- private Connection $connection;
-
- public function __construct(Connection $connection) {
- $this->connection = $connection;
+ public function __construct(
+ private Connection $connection,
+ ) {
parent::__construct();
}