Skip to content

Commit cec4176

Browse files
committed
Add support for pg_dump -n -N flags
--pg-namespace=PG-NAMESPACE translate to -n, --schema=SCHEMA dump the named schema(s) only --pg-exclude-namespace=PG-EXCLUDE-NAMESPACE translate to -N, --exclude-schema=SCHEMA do NOT dump the named schema(s)
1 parent 4b12625 commit cec4176

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Command/Db/DbDumpCommand.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ protected function configure()
2121
$this->setName('db:dump')
2222
->setDescription('Create a local dump of the remote database');
2323
$this->addOption('schema', null, InputOption::VALUE_REQUIRED, 'The schema to dump. Omit to use the default schema (usually "main").')
24+
->addOption('pg-namespace', null, InputOption::VALUE_REQUIRED| InputOption::VALUE_IS_ARRAY, 'Dump the named namespace/schema(s) only (Postgresql specific)')
25+
->addOption('pg-exclude-namespace', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Do NOT dump the named namespace/schema(s) (Postgresql specific)')
2426
->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'A custom filename for the dump')
2527
->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'A custom directory for the dump')
2628
->addOption('gzip', 'z', InputOption::VALUE_NONE, 'Compress the dump using gzip')
@@ -52,6 +54,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
5254
$gzip = $input->getOption('gzip');
5355
$includedTables = $input->getOption('table');
5456
$excludedTables = $input->getOption('exclude-table');
57+
$pgSchemas = $input->getOption('pg-namespace');
58+
$pgExcludedSchemas = $input->getOption('pg-exclude-namespace');
59+
5560
$schemaOnly = $input->getOption('schema-only');
5661
$projectRoot = $this->getProjectRoot();
5762

@@ -144,6 +149,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
144149
$schema,
145150
$includedTables,
146151
$excludedTables,
152+
$pgSchemas,
153+
$pgExcludedSchemas,
147154
$schemaOnly,
148155
$gzip
149156
);
@@ -202,6 +209,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
202209
foreach ($excludedTables as $table) {
203210
$dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--exclude-table=' . $table);
204211
}
212+
foreach ($pgSchemas as $pgSChema) {
213+
$dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--schema=' . $pgSChema);
214+
}
215+
foreach ($pgExcludedSchemas as $pgExcludedSChema) {
216+
$dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--exlude-schema=' . $pgExcludedSChema);
217+
}
205218
if ($input->getOption('charset') !== null) {
206219
$dumpCommand .= ' ' . OsUtil::escapePosixShellArg('--encoding=' . $input->getOption('charset'));
207220
}
@@ -309,6 +322,8 @@ private function getDefaultFilename(
309322
$schema = null,
310323
array $includedTables = [],
311324
array $excludedTables = [],
325+
array $pgSchemas = [],
326+
array $pgExcludedSchemas = [],
312327
$schemaOnly = false,
313328
$gzip = false)
314329
{
@@ -331,6 +346,12 @@ private function getDefaultFilename(
331346
if ($excludedTables) {
332347
$defaultFilename .= '--excl-' . implode(',', $excludedTables);
333348
}
349+
if ($pgSchemas){
350+
$defaultFilename .= '--n-' . implode(',', $pgSchemas);
351+
}
352+
if ($pgExcludedSchemas){
353+
$defaultFilename .= '--N-' . implode(',', $pgExcludedSchemas);
354+
}
334355
if ($schemaOnly) {
335356
$defaultFilename .= '--schema';
336357
}

0 commit comments

Comments
 (0)