From cd6a33eb47c8437270bf2acedd50a739dfda58a9 Mon Sep 17 00:00:00 2001 From: Adam Malone Date: Sun, 5 Apr 2020 08:56:13 +1000 Subject: [PATCH] Fixes #69: Adds in --no-backup option for code tasks to skip db backups. --- src/Commands/CodeCommand.php | 23 ++++++++++++++++++----- src/Commands/InsightsCommand.php | 2 +- tests/Commands/CodeCommandTest.php | 12 ++++++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Commands/CodeCommand.php b/src/Commands/CodeCommand.php index f4b35be..4032b25 100644 --- a/src/Commands/CodeCommand.php +++ b/src/Commands/CodeCommand.php @@ -65,13 +65,15 @@ public function code(Client $client, Code $codeAdapter, $uuid, $match = null) * @param string $environmentTo * * @command code:deploy + * @option no-backup Do not backup the database(s) prior to deploying code. * @aliases c:d */ public function codeDeploy( Code $codeAdapter, $uuid, $environmentFrom, - $environmentTo + $environmentTo, + $options = ['no-backup'] ) { $environmentFrom = $this->cloudapiService->getEnvironment($uuid, $environmentFrom); $environmentTo = $this->cloudapiService->getEnvironment($uuid, $environmentTo); @@ -88,7 +90,9 @@ public function codeDeploy( return; } - $this->backupAllEnvironmentDbs($uuid, $environmentTo); + if (!$options['no-backup']) { + $this->backupAllEnvironmentDbs($uuid, $environmentTo); + } $this->say( sprintf( @@ -110,10 +114,17 @@ public function codeDeploy( * @param string $branch * * @command code:switch + * @option no-backup Do not backup the database(s) prior to switching code. * @aliases c:s */ - public function codeSwitch(CloudApi $cloudapi, Code $codeAdapter, $uuid, $environment, $branch) - { + public function codeSwitch( + CloudApi $cloudapi, + Code $codeAdapter, + $uuid, + $environment, + $branch, + $options = ['no-backup'] + ) { $environment = $cloudapi->getEnvironment($uuid, $environment); if ( @@ -128,7 +139,9 @@ public function codeSwitch(CloudApi $cloudapi, Code $codeAdapter, $uuid, $enviro return; } - $this->backupAllEnvironmentDbs($uuid, $environment); + if (!$options['no-backup']) { + $this->backupAllEnvironmentDbs($uuid, $environment); + } $this->say(sprintf('Switching %s enviroment to %s branch', $environment->label, $branch)); diff --git a/src/Commands/InsightsCommand.php b/src/Commands/InsightsCommand.php index b22955b..6e453f4 100644 --- a/src/Commands/InsightsCommand.php +++ b/src/Commands/InsightsCommand.php @@ -118,7 +118,7 @@ public function insightsAlertsGet(Insights $insightsAdapter, $siteId, $alertUuid public function insightsModules( Insights $insightsAdapter, $siteId, - $options = ['enabled' => null, 'upgradeable' => null] + $options = ['enabled', 'upgradeable'] ) { $modules = $insightsAdapter->getModules($siteId); diff --git a/tests/Commands/CodeCommandTest.php b/tests/Commands/CodeCommandTest.php index 4f15cef..027f372 100644 --- a/tests/Commands/CodeCommandTest.php +++ b/tests/Commands/CodeCommandTest.php @@ -34,15 +34,23 @@ public function codeProvider() > Backing up DB (database2) on Stage > Deploying code from the Dev environment to the Stage environment'; + $codeDeployNoBackup = '> Deploying code from the Dev environment to the Stage environment'; + $codeSwitch = '> Backing up DB (database1) on Production > Backing up DB (database2) on Production > Switching Production enviroment to master branch'; + $codeSwitchNoBackup = '> Switching Production enviroment to master branch'; + return [ [ ['code:deploy', 'devcloud:devcloud2', 'dev', 'test'], $codeDeploy . PHP_EOL ], + [ + ['code:deploy', 'devcloud:devcloud2', 'dev', 'test', '--no-backup'], + $codeDeployNoBackup . PHP_EOL + ], [ ['code:list', 'devcloud:devcloud2'], $codeList . PHP_EOL @@ -52,8 +60,8 @@ public function codeProvider() $codeList . PHP_EOL ], [ - ['code:switch', 'devcloud:devcloud2', 'prod', 'master'], - $codeSwitch . PHP_EOL + ['code:switch', 'devcloud:devcloud2', 'prod', 'master', '--no-backup'], + $codeSwitchNoBackup . PHP_EOL ] ]; }