mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
pg_dump: reject combination of "only" and "with"
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/8ce896d1a05040905cc1a3afbc04e94d8e95669a.camel@j-davis.com Backpatch-through: 18
This commit is contained in:
@@ -860,6 +860,17 @@ main(int argc, char **argv)
|
|||||||
if (with_statistics && no_statistics)
|
if (with_statistics && no_statistics)
|
||||||
pg_fatal("options --with-statistics and --no-statistics cannot be used together");
|
pg_fatal("options --with-statistics and --no-statistics cannot be used together");
|
||||||
|
|
||||||
|
/* reject conflicting "-only" and "with-" options */
|
||||||
|
if (data_only && (with_schema || with_statistics))
|
||||||
|
pg_fatal("options %s and %s cannot be used together",
|
||||||
|
"-a/--data-only", with_schema ? "--with-schema" : "--with-statistics");
|
||||||
|
if (schema_only && (with_data || with_statistics))
|
||||||
|
pg_fatal("options %s and %s cannot be used together",
|
||||||
|
"-s/--schema-only", with_data ? "--with-data" : "--with-statistics");
|
||||||
|
if (statistics_only && (with_data || with_schema))
|
||||||
|
pg_fatal("options %s and %s cannot be used together",
|
||||||
|
"--statistics-only", with_data ? "--with-data" : "--with-schema");
|
||||||
|
|
||||||
if (schema_only && foreign_servers_include_patterns.head != NULL)
|
if (schema_only && foreign_servers_include_patterns.head != NULL)
|
||||||
pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together");
|
pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together");
|
||||||
|
|
||||||
@@ -873,11 +884,9 @@ main(int argc, char **argv)
|
|||||||
pg_fatal("option --if-exists requires option -c/--clean");
|
pg_fatal("option --if-exists requires option -c/--clean");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set derivative flags. An "-only" option may be overridden by an
|
* Set derivative flags. Ambiguous or nonsensical combinations, e.g.
|
||||||
* explicit "with-" option; e.g. "--schema-only --with-statistics" will
|
* "--schema-only --no-schema", will have already caused an error in one
|
||||||
* include schema and statistics. Other ambiguous or nonsensical
|
* of the checks above.
|
||||||
* combinations, e.g. "--schema-only --no-schema", will have already
|
|
||||||
* caused an error in one of the checks above.
|
|
||||||
*/
|
*/
|
||||||
dopt.dumpData = ((dopt.dumpData && !schema_only && !statistics_only) ||
|
dopt.dumpData = ((dopt.dumpData && !schema_only && !statistics_only) ||
|
||||||
(data_only || with_data)) && !no_data;
|
(data_only || with_data)) && !no_data;
|
||||||
|
@@ -381,6 +381,17 @@ main(int argc, char **argv)
|
|||||||
if (with_statistics && no_statistics)
|
if (with_statistics && no_statistics)
|
||||||
pg_fatal("options --with-statistics and --no-statistics cannot be used together");
|
pg_fatal("options --with-statistics and --no-statistics cannot be used together");
|
||||||
|
|
||||||
|
/* reject conflicting "only-" and "with-" options */
|
||||||
|
if (data_only && (with_schema || with_statistics))
|
||||||
|
pg_fatal("options %s and %s cannot be used together",
|
||||||
|
"-a/--data-only", with_schema ? "--with-schema" : "--with-statistics");
|
||||||
|
if (schema_only && (with_data || with_statistics))
|
||||||
|
pg_fatal("options %s and %s cannot be used together",
|
||||||
|
"-s/--schema-only", with_data ? "--with-data" : "--with-statistics");
|
||||||
|
if (statistics_only && (with_data || with_schema))
|
||||||
|
pg_fatal("options %s and %s cannot be used together",
|
||||||
|
"--statistics-only", with_data ? "--with-data" : "--with-schema");
|
||||||
|
|
||||||
if (data_only && opts->dropSchema)
|
if (data_only && opts->dropSchema)
|
||||||
pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
|
pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
|
||||||
|
|
||||||
@@ -399,11 +410,9 @@ main(int argc, char **argv)
|
|||||||
pg_fatal("cannot specify both --single-transaction and multiple jobs");
|
pg_fatal("cannot specify both --single-transaction and multiple jobs");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set derivative flags. An "-only" option may be overridden by an
|
* Set derivative flags. Ambiguous or nonsensical combinations, e.g.
|
||||||
* explicit "with-" option; e.g. "--schema-only --with-statistics" will
|
* "--schema-only --no-schema", will have already caused an error in one
|
||||||
* include schema and statistics. Other ambiguous or nonsensical
|
* of the checks above.
|
||||||
* combinations, e.g. "--schema-only --no-schema", will have already
|
|
||||||
* caused an error in one of the checks above.
|
|
||||||
*/
|
*/
|
||||||
opts->dumpData = ((opts->dumpData && !schema_only && !statistics_only) ||
|
opts->dumpData = ((opts->dumpData && !schema_only && !statistics_only) ||
|
||||||
(data_only || with_data)) && !no_data;
|
(data_only || with_data)) && !no_data;
|
||||||
|
@@ -799,13 +799,6 @@ my %pgdump_runs = (
|
|||||||
'postgres',
|
'postgres',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
schema_only_with_statistics => {
|
|
||||||
dump_cmd => [
|
|
||||||
'pg_dump', '--no-sync',
|
|
||||||
"--file=$tempdir/schema_only_with_statistics.sql",
|
|
||||||
'--schema-only', '--with-statistics', 'postgres',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
no_schema => {
|
no_schema => {
|
||||||
dump_cmd => [
|
dump_cmd => [
|
||||||
'pg_dump', '--no-sync',
|
'pg_dump', '--no-sync',
|
||||||
@@ -5207,6 +5200,17 @@ command_fails_like(
|
|||||||
qr/\Qpg_dump: error: no matching schemas were found for pattern\E/,
|
qr/\Qpg_dump: error: no matching schemas were found for pattern\E/,
|
||||||
'no matching schemas');
|
'no matching schemas');
|
||||||
|
|
||||||
|
command_fails_like(
|
||||||
|
[
|
||||||
|
'pg_dump',
|
||||||
|
'--port' => $port,
|
||||||
|
'--strict-names',
|
||||||
|
'--schema-only',
|
||||||
|
'--with-statistics',
|
||||||
|
],
|
||||||
|
qr/\Qpg_dump: error: options -s\/--schema-only and --with-statistics cannot be used together\E/,
|
||||||
|
'cannot use --schema-only and --with-statistics together');
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[
|
[
|
||||||
'pg_dump',
|
'pg_dump',
|
||||||
|
Reference in New Issue
Block a user