diff options
author | Joas Schilling <coding@schilljs.com> | 2020-11-10 21:28:39 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-11-11 11:45:00 +0100 |
commit | dde0e73c6b64194031db3203f921e8bdc0cb829d (patch) | |
tree | 0d79d2fb201e8e61c94b37421821d45b603fd84b | |
parent | 7f45f907893368ef5cc1b3d87c2151d4b8d304ce (diff) | |
download | nextcloud-server-dde0e73c6b64194031db3203f921e8bdc0cb829d.tar.gz nextcloud-server-dde0e73c6b64194031db3203f921e8bdc0cb829d.zip |
Reduce the number of schemas we generate when we just run all migrations anyway
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/DB/MigrationService.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index cd0280162d3..138d7703597 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) { @@ -416,6 +421,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 * * @param string $to |