Add optional version parameter to console updatedb
This commit is contained in:
parent
cd809f7646
commit
b0142f6ab2
|
@ -37,12 +37,14 @@ class UpdateDb extends \Asika\SimpleConsole\Console
|
||||||
$help = <<<HELP
|
$help = <<<HELP
|
||||||
console updatedb - Update database schema
|
console updatedb - Update database schema
|
||||||
Usage
|
Usage
|
||||||
bin/console updatedb [-h|--help|-?] [-v]
|
bin/console updatedb [<version>] [-h|--help|-?] [-v]
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Update database schema
|
Update database schema
|
||||||
|
|
||||||
Options
|
Options
|
||||||
|
<version> Optional target version number, default is the latest version.
|
||||||
|
Do not use this parameter if you're not sure what you're doing, it will result in data loss!
|
||||||
-h|--help|-? Show help information
|
-h|--help|-? Show help information
|
||||||
-v Show more debug information.
|
-v Show more debug information.
|
||||||
HELP;
|
HELP;
|
||||||
|
@ -56,16 +58,38 @@ HELP;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->args) > 1) {
|
if (count($this->args) > 2) {
|
||||||
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
|
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currentVersion = $this->migration->getCurrentVersion()['version'];
|
||||||
|
|
||||||
|
$this->out('Database schema currently in version ' . $currentVersion);
|
||||||
|
|
||||||
|
if (count($this->args) == 1) {
|
||||||
$this->out('Updating database schema to latest version...');
|
$this->out('Updating database schema to latest version...');
|
||||||
|
|
||||||
$this->migration->up();
|
$this->migration->up();
|
||||||
|
|
||||||
$this->out('Database schema migrated to version ' . $this->migration->getCurrentVersion()['version']);
|
$this->out('Database schema migrated to version ' . $this->migration->getCurrentVersion()['version']);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$target = $this->getArgument(1);
|
||||||
|
|
||||||
|
if ($target > $currentVersion) {
|
||||||
|
$this->out('Updating database schema to version ' . $target);
|
||||||
|
$this->migration->up($target);
|
||||||
|
$this->out('Database schema migrated up to version ' . $this->migration->getCurrentVersion()['version']);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($target < $currentVersion) {
|
||||||
|
$this->out('Downgrading database schema to version ' . $target);
|
||||||
|
$this->migration->down($target);
|
||||||
|
$this->out('Database schema migrated down to version ' . $this->migration->getCurrentVersion()['version']);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out('Target version equal to current version, exiting.');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue