Skip to content

Commit

Permalink
Provide more option
Browse files Browse the repository at this point in the history
Add options to overwrite the configuration values for:
- `host`
- `port`
- `user`

Add an option to avoid structure information in the resulted dump.
  • Loading branch information
FrankGiesecke committed Jun 5, 2018
1 parent 00df57b commit 7f89397
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
{
"name": "Markus Fasselt",
"email": "markus.fasselt@gmail.com"
},
{
"name": "Frank Giesecke",
"email": "frank.giesecke@final-gene.de"
}
],
"bin": ["bin/snakedumper"],
Expand Down
18 changes: 17 additions & 1 deletion src/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ protected function configure()
->addArgument('config', InputArgument::REQUIRED, 'The path to your config file.')
->addOption('progress', null, InputOption::VALUE_NONE, 'Show a progress bar')
->addOption('disable-limits', null, InputOption::VALUE_NONE, 'Create a full database dump')
->addOption('dbname', null, InputOption::VALUE_REQUIRED, 'Override the name of database that should be dumped')
->addOption('disable-structure', null, InputOption::VALUE_NONE, 'Create a dump containing data only')
->addOption('host', 'H', InputOption::VALUE_REQUIRED, 'Override the configured host')
->addOption('port', 'P', InputOption::VALUE_REQUIRED, 'Override the configured port')
->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'Override the configured user')
->addOption('password', 'p', InputOption::VALUE_REQUIRED, 'Override the configured password')
->addOption('dbname', null, InputOption::VALUE_REQUIRED, 'Override the name of database that should be dumped')
;
}

Expand Down Expand Up @@ -92,13 +96,25 @@ private function overrideConfigs(DumperConfigurationInterface $config, InputInte
if ($input->getOption('dbname') !== null) {
$config->getDatabaseConfig()->setDatabaseName($input->getOption('dbname'));
}
if ($input->getOption('user') !== null) {
$config->getDatabaseConfig()->setUser($input->getOption('user'));
}
if ($input->getOption('password') !== null) {
$config->getDatabaseConfig()->setPassword($input->getOption('password'));
}
if ($input->getOption('host') !== null) {
$config->getDatabaseConfig()->setHost($input->getOption('host'));
}
if ($input->getOption('port') !== null) {
$config->getDatabaseConfig()->setPort($input->getOption('port'));
}
if ($input->getOption('disable-limits')) {
foreach ($config->getTableConfigs() as $tableConfig) {
$tableConfig->setLimit(null);
}
}
if ($input->getOption('disable-structure')) {
$config->setIgnoreStructure(true);
}
}
}
25 changes: 25 additions & 0 deletions src/Configuration/SqlDumperConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class SqlDumperConfiguration extends AbstractConfiguration implements DumperConf
*/
private $tableConfigs = array();

/**
* @var bool
*/
private $ignoreStructure = false;

/**
* @return DatabaseConfiguration
*/
Expand Down Expand Up @@ -163,4 +168,24 @@ protected function parseConfig(array $dumperConfig)

$this->parseDependencies();
}

/**
* Get ignore structure.
*
* @return bool
*/
public function isIgnoreStructure()
{
return $this->ignoreStructure;
}

/**
* Set ignore structure.
*
* @param bool $ignoreStructure
*/
public function setIgnoreStructure($ignoreStructure)
{
$this->ignoreStructure = $ignoreStructure;
}
}
4 changes: 3 additions & 1 deletion src/Dumper/SqlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function dump(DumperContextInterface $context)
);

$this->dumpPreamble($context);
$structureDumper->dumpTableStructure($tables);
if (!$context->getConfig()->isIgnoreStructure()) {
$structureDumper->dumpTableStructure($tables);
}
$this->dumpTables($context, $tables);
$structureDumper->dumpConstraints($tables);
}
Expand Down

0 comments on commit 7f89397

Please sign in to comment.