1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-16 17:07:43 +03:00

Check existency of table/schema for -t/-n option (pg_dump/pg_restore)

Patch provides command line option --strict-names which requires that at
least one table/schema should present for each -t/-n option.

Pavel Stehule <pavel.stehule@gmail.com>
This commit is contained in:
Teodor Sigaev
2015-09-14 16:19:49 +03:00
parent b5217d6968
commit d02426029b
8 changed files with 161 additions and 34 deletions

View File

@@ -108,6 +108,9 @@ static void reduce_dependencies(ArchiveHandle *AH, TocEntry *te,
static void mark_create_done(ArchiveHandle *AH, TocEntry *te);
static void inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te);
static void StrictNamesCheck(RestoreOptions *ropt);
/*
* Allocate a new DumpOptions block containing all default values.
*/
@@ -284,6 +287,10 @@ SetArchiveRestoreOptions(Archive *AHX, RestoreOptions *ropt)
te->reqs = _tocEntryRequired(te, curSection, ropt);
}
/* Enforce strict names checking */
if (ropt->strict_names)
StrictNamesCheck(ropt);
}
/* Public */
@@ -1104,6 +1111,10 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
}
}
/* Enforce strict names checking */
if (ropt->strict_names)
StrictNamesCheck(ropt);
if (ropt->filename)
RestoreOutput(AH, sav);
}
@@ -2612,6 +2623,49 @@ processStdStringsEntry(ArchiveHandle *AH, TocEntry *te)
te->defn);
}
static void
StrictNamesCheck(RestoreOptions *ropt)
{
const char *missing_name;
Assert(ropt->strict_names);
if (ropt->schemaNames.head != NULL)
{
missing_name = simple_string_list_not_touched(&ropt->schemaNames);
if (missing_name != NULL)
exit_horribly(modulename, "Schema \"%s\" not found.\n", missing_name);
}
if (ropt->tableNames.head != NULL)
{
missing_name = simple_string_list_not_touched(&ropt->tableNames);
if (missing_name != NULL)
exit_horribly(modulename, "Table \"%s\" not found.\n", missing_name);
}
if (ropt->indexNames.head != NULL)
{
missing_name = simple_string_list_not_touched(&ropt->indexNames);
if (missing_name != NULL)
exit_horribly(modulename, "Index \"%s\" not found.\n", missing_name);
}
if (ropt->functionNames.head != NULL)
{
missing_name = simple_string_list_not_touched(&ropt->functionNames);
if (missing_name != NULL)
exit_horribly(modulename, "Function \"%s\" not found.\n", missing_name);
}
if (ropt->triggerNames.head != NULL)
{
missing_name = simple_string_list_not_touched(&ropt->triggerNames);
if (missing_name != NULL)
exit_horribly(modulename, "Trigger \"%s\" not found.\n", missing_name);
}
}
static teReqs
_tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
{