From 7ee982005acfebe2a88b10b94d092161b0cf91e2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Apr 2022 16:21:25 +0200 Subject: [PATCH 1/2] Give hints on correct migration versioning Signed-off-by: Joas Schilling --- .../Command/Db/Migrations/GenerateCommand.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php index 1710816cbba66..f35e49126a196 100644 --- a/core/Command/Db/Migrations/GenerateCommand.php +++ b/core/Command/Db/Migrations/GenerateCommand.php @@ -28,6 +28,7 @@ use OC\DB\MigrationService; use OC\Migration\ConsoleOutput; use OCP\App\IAppManager; +use OCP\Util; use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Command\Command; @@ -35,6 +36,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; class GenerateCommand extends Command implements CompletionAwareInterface { protected static $_templateSimple = @@ -140,6 +142,36 @@ public function execute(InputInterface $input, OutputInterface $output): int { return 1; } + if ($appName === 'core') { + $fullVersion = implode('.', Util::getVersion()); + } else { + try { + $fullVersion = $this->appManager->getAppVersion($appName, false); + } catch (\Throwable $e) { + $fullVersion = ''; + } + } + + if ($fullVersion) { + [$major, $minor] = explode('.', $fullVersion); + $shouldVersion = $major * 1000 + $minor; + if ($version !== $shouldVersion) { + $output->writeln('Unexpected migration version for current version: ' . $fullVersion . ''); + $output->writeln(' - Pattern: XYYY '); + $output->writeln(' - Expected: ' . $shouldVersion . ''); + $output->writeln(' - Actual: ' . $version . ''); + + if ($input->isInteractive()) { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion('Continue with your given version? (y/n) [n] ', false); + + if (!$helper->ask($input, $output, $question)) { + return 1; + } + } + } + } + $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); $date = date('YmdHis'); From 2ffcc08332632cddc64236917c35659939ec4f97 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Apr 2022 16:49:23 +0200 Subject: [PATCH 2/2] Fix type fixing Signed-off-by: Joas Schilling --- core/Command/Db/Migrations/GenerateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php index f35e49126a196..9790a96a0fd1a 100644 --- a/core/Command/Db/Migrations/GenerateCommand.php +++ b/core/Command/Db/Migrations/GenerateCommand.php @@ -154,7 +154,7 @@ public function execute(InputInterface $input, OutputInterface $output): int { if ($fullVersion) { [$major, $minor] = explode('.', $fullVersion); - $shouldVersion = $major * 1000 + $minor; + $shouldVersion = (int)$major * 1000 + (int)$minor; if ($version !== $shouldVersion) { $output->writeln('Unexpected migration version for current version: ' . $fullVersion . ''); $output->writeln(' - Pattern: XYYY ');