From 891de38080f27011cb050301c7948b52e3141470 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2018 15:32:36 +0200 Subject: [PATCH] Only create the schema when moving between databases Signed-off-by: Joas Schilling --- core/Command/Db/ConvertType.php | 2 +- lib/private/DB/MigrationService.php | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php index 7fdf1f39b8..b6c2c66b3d 100644 --- a/core/Command/Db/ConvertType.php +++ b/core/Command/Db/ConvertType.php @@ -245,7 +245,7 @@ class ConvertType extends Command implements CompletionAwareInterface { $currentMigration = $fromMS->getMigration('current'); if ($currentMigration !== '0') { $toMS = new MigrationService($app, $toDB); - $toMS->migrate($currentMigration); + $toMS->migrate($currentMigration, true); } } } diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index cc2889dae0..6f5a74103a 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -376,13 +376,14 @@ class MigrationService { * Applies all not yet applied versions up to $to * * @param string $to + * @param bool $schemaOnly * @throws \InvalidArgumentException */ - public function migrate($to = 'latest') { + public function migrate($to = 'latest', $schemaOnly = false) { // read known migrations $toBeExecuted = $this->getMigrationsToExecute($to); foreach ($toBeExecuted as $version) { - $this->executeStep($version); + $this->executeStep($version, $schemaOnly); } } @@ -432,14 +433,17 @@ class MigrationService { * Executes one explicit version * * @param string $version + * @param bool $schemaOnly * @throws \InvalidArgumentException */ - public function executeStep($version) { + public function executeStep($version, $schemaOnly = false) { $instance = $this->createInstance($version); - $instance->preSchemaChange($this->output, function() { - return new SchemaWrapper($this->connection); - }, ['tablePrefix' => $this->connection->getPrefix()]); + if (!$schemaOnly) { + $instance->preSchemaChange($this->output, function() { + return new SchemaWrapper($this->connection); + }, ['tablePrefix' => $this->connection->getPrefix()]); + } $toSchema = $instance->changeSchema($this->output, function() { return new SchemaWrapper($this->connection); @@ -450,9 +454,11 @@ class MigrationService { $toSchema->performDropTableCalls(); } - $instance->postSchemaChange($this->output, function() { - return new SchemaWrapper($this->connection); - }, ['tablePrefix' => $this->connection->getPrefix()]); + if (!$schemaOnly) { + $instance->postSchemaChange($this->output, function() { + return new SchemaWrapper($this->connection); + }, ['tablePrefix' => $this->connection->getPrefix()]); + } $this->markAsExecuted($version); }