Skip to content

Commit

Permalink
Fixes #69: Adds in --no-backup option for code tasks to skip db backu…
Browse files Browse the repository at this point in the history
…ps. (#70)
  • Loading branch information
typhonius authored Apr 4, 2020
1 parent 555ea9b commit a7b71c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/Commands/CodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -88,7 +90,9 @@ public function codeDeploy(
return;
}
$this->backupAllEnvironmentDbs($uuid, $environmentTo);
if (!$options['no-backup']) {
$this->backupAllEnvironmentDbs($uuid, $environmentTo);
}
$this->say(
sprintf(
Expand All @@ -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 (
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/InsightsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 12 additions & 0 deletions tests/Commands/CodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,6 +62,10 @@ public function codeProvider()
[
['code:switch', 'devcloud:devcloud2', 'prod', 'master'],
$codeSwitch . PHP_EOL
],
[
['code:switch', 'devcloud:devcloud2', 'prod', 'master', '--no-backup'],
$codeSwitchNoBackup . PHP_EOL
]
];
}
Expand Down

0 comments on commit a7b71c2

Please sign in to comment.