From 7f45f907893368ef5cc1b3d87c2151d4b8d304ce Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Nov 2020 21:26:41 +0100 Subject: [PATCH 1/3] Only update the schema when we install anyway Signed-off-by: Joas Schilling --- lib/private/Installer.php | 4 ++-- lib/private/Setup/AbstractDatabase.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/Installer.php b/lib/private/Installer.php index 9388711697..96f14933a7 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -154,7 +154,7 @@ class Installer { } } else { $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); - $ms->migrate(); + $ms->migrate('latest', true); } if ($previousVersion) { OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']); @@ -589,7 +589,7 @@ class Installer { } } else { $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); - $ms->migrate(); + $ms->migrate('latest', true); } //run appinfo/install.php diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php index 98d6b84ab9..8a9aed09f1 100644 --- a/lib/private/Setup/AbstractDatabase.php +++ b/lib/private/Setup/AbstractDatabase.php @@ -150,6 +150,6 @@ abstract class AbstractDatabase { return; } $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); - $ms->migrate(); + $ms->migrate('latest', true); } } From dde0e73c6b64194031db3203f921e8bdc0cb829d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Nov 2020 21:28:39 +0100 Subject: [PATCH 2/3] Reduce the number of schemas we generate when we just run all migrations anyway Signed-off-by: Joas Schilling --- lib/private/DB/MigrationService.php | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index cd0280162d..138d770359 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -408,6 +408,11 @@ class MigrationService { * @throws \InvalidArgumentException */ public function migrate($to = 'latest', $schemaOnly = false) { + if ($schemaOnly) { + $this->migrateSchemaOnly($to); + return; + } + // read known migrations $toBeExecuted = $this->getMigrationsToExecute($to); foreach ($toBeExecuted as $version) { @@ -415,6 +420,42 @@ class MigrationService { } } + /** + * Applies all not yet applied versions up to $to + * + * @param string $to + * @throws \InvalidArgumentException + */ + public function migrateSchemaOnly($to = 'latest') { + // read known migrations + $toBeExecuted = $this->getMigrationsToExecute($to); + + if (empty($toBeExecuted)) { + return; + } + + $toSchema = null; + foreach ($toBeExecuted as $version) { + $instance = $this->createInstance($version); + + $toSchema = $instance->changeSchema($this->output, function () use ($toSchema) { + return $toSchema ?: new SchemaWrapper($this->connection); + }, ['tablePrefix' => $this->connection->getPrefix()]) ?: $toSchema; + + $this->markAsExecuted($version); + } + + if ($toSchema instanceof SchemaWrapper) { + $targetSchema = $toSchema->getWrappedSchema(); + if ($this->checkOracle) { + $beforeSchema = $this->connection->createSchema(); + $this->ensureOracleIdentifierLengthLimit($beforeSchema, $targetSchema, strlen($this->connection->getPrefix())); + } + $this->connection->migrateToSchema($targetSchema); + $toSchema->performDropTableCalls(); + } + } + /** * Get the human readable descriptions for the migration steps to run * From 77713ab454f7edb99502cc706b6b08b32d8fa177 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Nov 2020 21:29:09 +0100 Subject: [PATCH 3/3] Don't create a schema to check if the migrations table exists Signed-off-by: Joas Schilling --- lib/private/DB/MigrationService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 138d770359..9c94cbc61f 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -124,6 +124,11 @@ class MigrationService { return false; } + if ($this->connection->tableExists('migrations')) { + $this->migrationTableCreated = true; + return false; + } + $schema = new SchemaWrapper($this->connection); /**