Skip to content

Commit

Permalink
Merge pull request #5 from FrankGiesecke/4-provide-more-options
Browse files Browse the repository at this point in the history
Provide more options
  • Loading branch information
digilist authored Jun 6, 2018
2 parents 00df57b + 16beddf commit df357ae
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
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 df357ae

Please sign in to comment.