Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-06-07 13:27:16 +0300
committerMorris Jobke <hey@morrisjobke.de>2017-07-05 14:01:19 +0300
commit817783e4c7e93fc7bf3bdb50a014966415e19605 (patch)
tree4584b9273888ab1f1ebbbbd62524670be9ad75db /core/Command/Db/Migrations
parentdf6b839b2347531641864dbc408ab445169ffec6 (diff)
Add a version to migrations, so parallel legacy branches can also have migrations
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/Command/Db/Migrations')
-rw-r--r--core/Command/Db/Migrations/GenerateCommand.php28
1 files changed, 19 insertions, 9 deletions
diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php
index 8614be0a507..92d8e15b66c 100644
--- a/core/Command/Db/Migrations/GenerateCommand.php
+++ b/core/Command/Db/Migrations/GenerateCommand.php
@@ -40,13 +40,14 @@ class GenerateCommand extends Command {
'<?php
namespace <namespace>;
+use Doctrine\DBAL\Schema\Schema;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
/**
* Auto-generated migration step: Please modify to your needs!
*/
-class Version<version> extends SimpleMigrationStep {
+class <classname> extends SimpleMigrationStep {
/**
* @param IOutput $output
@@ -90,6 +91,7 @@ class Version<version> extends SimpleMigrationStep {
$this
->setName('migrations:generate')
->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
+ ->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches')
;
parent::configure();
@@ -97,31 +99,39 @@ class Version<version> extends SimpleMigrationStep {
public function execute(InputInterface $input, OutputInterface $output) {
$appName = $input->getArgument('app');
+ $version = $input->getArgument('version');
+
+ if (!preg_match('/^\d{1,16}$/',$version)) {
+ $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
+ return 1;
+ }
+
$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
- $version = date('YmdHis');
- $path = $this->generateMigration($ms, $version);
- $output->writeln("New migration class has been generated to <info>$path</info>");
+ $date = date('YmdHis');
+ $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
+ $output->writeln("New migration class has been generated to <info>$path</info>");
+ return 0;
}
/**
* @param MigrationService $ms
- * @param string $version
+ * @param string $className
* @return string
*/
- private function generateMigration(MigrationService $ms, $version) {
+ private function generateMigration(MigrationService $ms, $className) {
$placeHolders = [
'<namespace>',
- '<version>',
+ '<classname>',
];
$replacements = [
$ms->getMigrationsNamespace(),
- $version,
+ $className,
];
$code = str_replace($placeHolders, $replacements, self::$_templateSimple);
$dir = $ms->getMigrationsDirectory();
- $path = $dir . '/Version' . $version . '.php';
+ $path = $dir . '/' . $className . '.php';
if (file_put_contents($path, $code) === false) {
throw new RuntimeException('Failed to generate new migration step.');