-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commands support for Warden Docker db container
- Loading branch information
Showing
14 changed files
with
852 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Commands\Warden; | ||
|
||
use LaravelZero\Framework\Commands\Command; | ||
use App\Traits\Command as AppCommand; | ||
use App\Commands\Dump\CleanCommand; | ||
|
||
class BackupCommand extends Command | ||
{ | ||
use AppCommand; | ||
|
||
const COMMAND = 'warden:db:backup'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $signature = self::COMMAND | ||
. ' {file? : File name}' | ||
. ' {--t|tag= : A tag of the dump file}' | ||
. ' {--s|strip= : Tables to strip (dump only structure of those tables)}' | ||
. ' {--no-progress : Do not display progress}' | ||
. ' {--print : Print command only, not run it}' | ||
. ' {--skip-filter : Do not filter DEFINER and ROW_FORMAT}' | ||
. ' {--compatibility : mysqldump 8 backward compatible with MySQL 5.7}' | ||
. ' {--c|clean= : The number of latest dumps to keep, other will be removed}' | ||
. ' {--f|force : Overwrite dump file if it already exits locally}' | ||
. ' {--k|keep-file : Keep dump file}'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Export and upload DB from Warden db container to AWS'; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
$this->call( | ||
ExportCommand::COMMAND, | ||
[ | ||
'file' => $this->argument('file'), | ||
'--magento-directory' => $this->option('magento-directory'), | ||
'--db-host' => $this->option('db-host'), | ||
'--db-port' => $this->option('db-port'), | ||
'--db-name' => $this->option('db-name'), | ||
'--db-username' => $this->option('db-username'), | ||
'--db-password' => $this->option('db-password'), | ||
'--storage' => $this->option('storage'), | ||
'--aws-bucket' => $this->option('aws-bucket'), | ||
'--aws-access-key' => $this->option('aws-access-key'), | ||
'--aws-secret-key' => $this->option('aws-secret-key'), | ||
'--aws-region' => $this->option('aws-region'), | ||
'--tag' => $this->option('tag'), | ||
'--strip' => $this->option('strip'), | ||
'--compatibility' => $this->option('compatibility'), | ||
'--no-progress' => $this->option('no-progress'), | ||
'--print' => $this->option('print'), | ||
'--skip-filter' => $this->option('skip-filter'), | ||
'--project' => $this->option('project'), | ||
'--force' => $this->option('force'), | ||
'--quiet' => $this->option('quiet'), | ||
'--upload' => true, | ||
'--remove-file' => !$this->option('keep-file') | ||
] | ||
); | ||
|
||
$clean = (int)$this->option('clean'); | ||
if ($clean > 0) { | ||
$this->call( | ||
CleanCommand::COMMAND, | ||
[ | ||
'count' => $clean, | ||
'--project' => $this->option('project'), | ||
'--tag' => $this->option('tag'), | ||
] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Commands\Warden; | ||
|
||
use App\Services\WardenDatabase; | ||
use App\Traits\Command as AppCommand; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class CreateCommand extends Command | ||
{ | ||
use AppCommand; | ||
|
||
const COMMAND = 'warden:db:create'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $signature = self::COMMAND | ||
. ' {name? : Database name}' | ||
. ' {--f|force : Re-create if DB with the same name already exists}'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Create Database from Warden db container'; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
$dbName = $this->argument('name'); | ||
|
||
if ($this->option('force')) { | ||
$this->call(DropCommand::COMMAND, ['name' => $dbName]); | ||
} | ||
|
||
$taskMessage = $dbName | ||
? sprintf('Create DB %s if not exists', $dbName) | ||
: 'Create DB if not exists'; | ||
|
||
$this->task($taskMessage, static function () use ($dbName) { | ||
try { | ||
$wardenCommand = WardenDatabase::createWardenDbCommand('create'); | ||
if ($dbName) { | ||
$wardenCommand->argument($dbName); | ||
} | ||
$wardenCommand->exec(); | ||
|
||
$result = true; | ||
} catch (\Symfony\Component\Process\Exception\ProcessFailedException $e) { | ||
$result = $e->getProcess()->getCommandLine(); | ||
} catch (\Exception $e) { | ||
$result = $e->getMessage(); | ||
} | ||
return $result; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Commands\Warden; | ||
|
||
use App\Traits\Command as AppCommand; | ||
use App\Services\WardenDatabase; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class DropCommand extends Command | ||
{ | ||
use AppCommand; | ||
|
||
const COMMAND = 'warden:db:drop'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $signature = self::COMMAND | ||
. ' {name? : Database name}'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Drop Database from Warden db container'; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
$dbName = $this->argument('name'); | ||
|
||
$taskMessage = $dbName | ||
? sprintf('Drop DB "%s" if exists', $dbName) | ||
: 'Drop DB if exists'; | ||
|
||
$this->task($taskMessage, static function () use ($dbName) { | ||
try { | ||
|
||
$wardenCommand = WardenDatabase::createWardenDbCommand('drop'); | ||
if ($dbName) { | ||
$wardenCommand->argument($dbName); | ||
} | ||
$wardenCommand->exec(); | ||
|
||
$result = true; | ||
} catch (\Symfony\Component\Process\Exception\ProcessFailedException $e) { | ||
$result = $e->getProcess()->getCommandLine(); | ||
} catch (\Exception $e) { | ||
$result = $e->getMessage(); | ||
} | ||
return $result; | ||
}); | ||
} | ||
} |
Oops, something went wrong.