Skip to content

Commit

Permalink
Merge pull request #10298 from nextcloud/bugfix/talk-714/only-migrate…
Browse files Browse the repository at this point in the history
…-the-schema-when-moving-database

Only create the schema when moving between databases
  • Loading branch information
MorrisJobke committed Jul 24, 2018
2 parents d67e18b + 891de38 commit 7da815b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/Command/Db/ConvertType.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected function createSchema(Connection $fromDB, Connection $toDB, InputInter
$currentMigration = $fromMS->getMigration('current');
if ($currentMigration !== '0') {
$toMS = new MigrationService($app, $toDB);
$toMS->migrate($currentMigration);
$toMS->migrate($currentMigration, true);
}
}
}
Expand Down
24 changes: 15 additions & 9 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,14 @@ public function setOutput(IOutput $output) {
* 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);
}
}

Expand Down Expand Up @@ -432,14 +433,17 @@ protected function createInstance($version) {
* 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);
Expand All @@ -450,9 +454,11 @@ public function executeStep($version) {
$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);
}
Expand Down

0 comments on commit 7da815b

Please sign in to comment.