Skip to content

Commit

Permalink
Create a moveDbs() function that does not backup dbs first and read -…
Browse files Browse the repository at this point in the history
…-no-backup option for database:copy:all.
  • Loading branch information
earthday47 committed Oct 9, 2020
1 parent e8c9880 commit a028ab2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,42 @@ protected function waitForNotification($response)
}

/**
* Copy all DBs from one environment to another without backing up first.
*
* @param string $uuid
* @param EnvironmentResponse $environmentFrom
* @param EnvironmentResponse $environmentTo
*/
protected function moveDbs($uuid, $environmentFrom, $environmentTo, $dbName = null)
{
if (null !== $dbName) {
$this->cloudapi->addQuery('filter', "name=${dbName}");
}

$dbAdapter = new Databases($this->cloudapi);
$databases = $dbAdapter->getAll($uuid);
$this->cloudapi->clearQuery();

foreach ($databases as $database) {
// Copy DB from prod to non-prod.
$this->say(
sprintf(
'Moving DB (%s) from %s to %s',
$database->name,
$environmentFrom->label,
$environmentTo->label
)
);

$databaseAdapter = new Databases($this->cloudapi);
$response = $databaseAdapter->copy($environmentFrom->uuid, $database->name, $environmentTo->uuid);
$this->waitForNotification($response);
}
}

/**
* Backup and copy all DBs from one environment to another.
*
* @param string $uuid
* @param EnvironmentResponse $environmentFrom
* @param EnvironmentResponse $environmentTo
Expand Down
11 changes: 9 additions & 2 deletions src/Commands/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ public function dbCopy($uuid, $environmentFrom, $environmentTo, $dbName)
* @param string $environmentTo
*
* @command database:copy:all
* @option no-backup Do not backup the databases on production.
* @aliases db:copy:all
*/
public function dbCopyAll($uuid, $environmentFrom, $environmentTo)
public function dbCopyAll($uuid, $environmentFrom, $environmentTo, $options = [])
{
$environmentFrom = $this->cloudapiService->getEnvironment($uuid, $environmentFrom);
$environmentTo = $this->cloudapiService->getEnvironment($uuid, $environmentTo);
Expand All @@ -151,7 +152,13 @@ public function dbCopyAll($uuid, $environmentFrom, $environmentTo)
)
)
) {
$this->backupAndMoveDbs($uuid, $environmentFrom, $environmentTo);

if (isset($options['no-backup']) && $options['no-backup']) {
$this->moveDbs($uuid, $environmentFrom, $environmentTo);
}
else {
$this->backupAndMoveDbs($uuid, $environmentFrom, $environmentTo);
}
}
}
}

0 comments on commit a028ab2

Please sign in to comment.