diff --git a/module/CLI/src/Command/Install/AbstractInstallCommand.php b/module/CLI/src/Command/Install/AbstractInstallCommand.php index 9b186281..5c271231 100644 --- a/module/CLI/src/Command/Install/AbstractInstallCommand.php +++ b/module/CLI/src/Command/Install/AbstractInstallCommand.php @@ -100,9 +100,15 @@ abstract class AbstractInstallCommand extends Command $this->configWriter->toFile('config/params/generated_config.php', $config, false); $output->writeln(['Custom configuration properly generated!', '']); - // Generate database - if (! $this->createDatabase()) { - return; + // If current command is not update, generate database + if (! $this->isUpdate()) { + $this->output->writeln('Initializing database...'); + if (! $this->runCommand( + 'php vendor/bin/doctrine.php orm:schema-tool:create', + 'Error generating database.' + )) { + return; + } } // Run database migrations @@ -295,11 +301,6 @@ abstract class AbstractInstallCommand extends Command return $config; } - /** - * @return bool - */ - abstract protected function createDatabase(); - /** * @param string $command * @param string $errorMessage @@ -322,4 +323,9 @@ abstract class AbstractInstallCommand extends Command ); return false; } + + /** + * @return bool + */ + abstract protected function isUpdate(); } diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php index a8e07de1..e414bbe0 100644 --- a/module/CLI/src/Command/Install/InstallCommand.php +++ b/module/CLI/src/Command/Install/InstallCommand.php @@ -3,9 +3,11 @@ namespace Shlinkio\Shlink\CLI\Command\Install; class InstallCommand extends AbstractInstallCommand { - protected function createDatabase() + /** + * @return bool + */ + protected function isUpdate() { - $this->output->writeln('Initializing database...'); - return $this->runCommand('php vendor/bin/doctrine.php orm:schema-tool:create', 'Error generating database.'); + return false; } } diff --git a/module/CLI/src/Command/Install/UpdateCommand.php b/module/CLI/src/Command/Install/UpdateCommand.php index def28d06..425dc06a 100644 --- a/module/CLI/src/Command/Install/UpdateCommand.php +++ b/module/CLI/src/Command/Install/UpdateCommand.php @@ -3,7 +3,10 @@ namespace Shlinkio\Shlink\CLI\Command\Install; class UpdateCommand extends AbstractInstallCommand { - public function createDatabase() + /** + * @return bool + */ + protected function isUpdate() { return true; }