Only create the schema when moving between databases

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-07-19 15:32:36 +02:00
parent 596655fa1a
commit 891de38080
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 16 additions and 10 deletions

View File

@ -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);
}
}
}

View File

@ -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);
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();
}
if (!$schemaOnly) {
$instance->postSchemaChange($this->output, function() {
return new SchemaWrapper($this->connection);
}, ['tablePrefix' => $this->connection->getPrefix()]);
}
$this->markAsExecuted($version);
}