Skip to content

Commit

Permalink
[FEATURE] Add db:push command.
Browse files Browse the repository at this point in the history
  • Loading branch information
kszymukowicz committed Feb 15, 2020
1 parent 9a09032 commit 3f69149
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

Changelog
---------
master
~~~~~~

1) [FEATURE] Add db:push command.

9.0.0
~~~~~~
Expand Down
34 changes: 34 additions & 0 deletions deployer/db/task/db_push.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Deployer;

use SourceBroker\DeployerExtendedDatabase\Utility\ConsoleUtility;
use Deployer\Exception\GracefulShutdownException;

/*
* @see https://github.com/sourcebroker/deployer-extended-database#db-push
*/
task('db:push', function () {
$targetName = get('argument_stage');
if (null !== $targetName) {
if (!get('db_allow_push_live', false) && $targetName === get('instance_live_name', 'live')) {
throw new GracefulShutdownException(
'FORBIDDEN: For security its forbidden to push media to "'
. get('instance_live_name', 'live') . '" instance!' .
' Use "set(\'db_allow_push_live\', true);" to allow this. [Error code: 1488149981778]'
);
}
} else {
throw new GracefulShutdownException("The target instance is required for media:push command. [Error code: 1488149981776]");
}

$dumpCode = md5(microtime(true) . rand(0, 10000));
$dl = get('local/bin/deployer');
$verbosity = (new ConsoleUtility())->getVerbosityAsParameter();
$options = (new ConsoleUtility())->getOptionsForCliUsage(['dumpcode' => $dumpCode]);
runLocally($dl . ' db:export ' . $options . ' ' . $verbosity);
runLocally($dl . ' db:upload ' . $targetName . ' ' . $options . ' ' . $verbosity);
runLocally($dl . ' db:process ' . $targetName . ' ' . $options . ' ' . $verbosity);
runLocally($dl . ' db:import ' . $targetName . ' ' . $options . ' ' . $verbosity);
runLocally($dl . ' db:rmdump ' . $targetName . ' ' . $options . ' ' . $verbosity);
})->desc('Copy database from local to remote');

0 comments on commit 3f69149

Please sign in to comment.