diff --git a/src/Command/Db/DbDumpCommand.php b/src/Command/Db/DbDumpCommand.php index 1ba078e2a8..9e37c9004b 100644 --- a/src/Command/Db/DbDumpCommand.php +++ b/src/Command/Db/DbDumpCommand.php @@ -21,6 +21,8 @@ protected function configure() $this->setName('db:dump') ->setDescription('Create a local dump of the remote database'); $this->addOption('schema', null, InputOption::VALUE_REQUIRED, 'The schema to dump. Omit to use the default schema (usually "main").') + ->addOption('pg-namespace', null, InputOption::VALUE_REQUIRED| InputOption::VALUE_IS_ARRAY, 'Dump the named namespace/schema(s) only (Postgresql specific)') + ->addOption('pg-exclude-namespace', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Do NOT dump the named namespace/schema(s) (Postgresql specific)') ->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'A custom filename for the dump') ->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'A custom directory for the dump') ->addOption('gzip', 'z', InputOption::VALUE_NONE, 'Compress the dump using gzip') @@ -52,6 +54,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $gzip = $input->getOption('gzip'); $includedTables = $input->getOption('table'); $excludedTables = $input->getOption('exclude-table'); + $pgSchemas = $input->getOption('pg-namespace'); + $pgExcludedSchemas = $input->getOption('pg-exclude-namespace'); + $schemaOnly = $input->getOption('schema-only'); $projectRoot = $this->getProjectRoot(); @@ -144,6 +149,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $schema, $includedTables, $excludedTables, + $pgSchemas, + $pgExcludedSchemas, $schemaOnly, $gzip ); @@ -202,6 +209,12 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($excludedTables as $table) { $dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--exclude-table=' . $table); } + foreach ($pgSchemas as $pgSChema) { + $dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--schema=' . $pgSChema); + } + foreach ($pgExcludedSchemas as $pgExcludedSChema) { + $dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--exclude-schema=' . $pgExcludedSChema); + } if ($input->getOption('charset') !== null) { $dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--encoding=' . $input->getOption('charset')); } @@ -309,6 +322,8 @@ private function getDefaultFilename( $schema = null, array $includedTables = [], array $excludedTables = [], + array $pgSchemas = [], + array $pgExcludedSchemas = [], $schemaOnly = false, $gzip = false) { @@ -331,6 +346,12 @@ private function getDefaultFilename( if ($excludedTables) { $defaultFilename .= '--excl-' . implode(',', $excludedTables); } + if ($pgSchemas){ + $defaultFilename .= '--n-' . implode(',', $pgSchemas); + } + if ($pgExcludedSchemas){ + $defaultFilename .= '--N-' . implode(',', $pgExcludedSchemas); + } if ($schemaOnly) { $defaultFilename .= '--schema'; }