Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pg_dump -n and -N flags #1148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Command/Db/DbDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different than --schema above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes : with postgresql schema != database (not like mysql or mariadb)
"A database contains one or more named schemas, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database they are connected to, if they have privileges to do so."
https://www.postgresql.org/docs/current/ddl-schemas.html

->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')
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -144,6 +149,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$schema,
$includedTables,
$excludedTables,
$pgSchemas,
$pgExcludedSchemas,
$schemaOnly,
$gzip
);
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -309,6 +322,8 @@ private function getDefaultFilename(
$schema = null,
array $includedTables = [],
array $excludedTables = [],
array $pgSchemas = [],
array $pgExcludedSchemas = [],
$schemaOnly = false,
$gzip = false)
{
Expand All @@ -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';
}
Expand Down