mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Fix pg_dump to dump shell types.
Per discussion, it really ought to do this. The original choice to exclude shell types was probably made in the dark ages before we made it harder to accidentally create shell types; but that was in 7.3. Also, cause the standard regression tests to leave a shell type behind, for convenience in testing the case in pg_dump and pg_upgrade. Back-patch to all supported branches.
This commit is contained in:
@@ -171,6 +171,7 @@ static void dumpType(Archive *fout, TypeInfo *tyinfo);
|
||||
static void dumpBaseType(Archive *fout, TypeInfo *tyinfo);
|
||||
static void dumpEnumType(Archive *fout, TypeInfo *tyinfo);
|
||||
static void dumpRangeType(Archive *fout, TypeInfo *tyinfo);
|
||||
static void dumpUndefinedType(Archive *fout, TypeInfo *tyinfo);
|
||||
static void dumpDomain(Archive *fout, TypeInfo *tyinfo);
|
||||
static void dumpCompositeType(Archive *fout, TypeInfo *tyinfo);
|
||||
static void dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo);
|
||||
@@ -1186,11 +1187,6 @@ selectDumpableType(TypeInfo *tyinfo)
|
||||
/* dump only types in dumpable namespaces */
|
||||
if (!tyinfo->dobj.namespace->dobj.dump)
|
||||
tyinfo->dobj.dump = false;
|
||||
|
||||
/* skip undefined placeholder types */
|
||||
else if (!tyinfo->isDefined)
|
||||
tyinfo->dobj.dump = false;
|
||||
|
||||
else
|
||||
tyinfo->dobj.dump = true;
|
||||
}
|
||||
@@ -3101,7 +3097,7 @@ getTypes(Archive *fout, int *numTypes)
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(tyinfo[i].rolname) == 0 && tyinfo[i].isDefined)
|
||||
if (strlen(tyinfo[i].rolname) == 0)
|
||||
write_msg(NULL, "WARNING: owner of data type \"%s\" appears to be invalid\n",
|
||||
tyinfo[i].dobj.name);
|
||||
}
|
||||
@@ -7516,6 +7512,8 @@ dumpType(Archive *fout, TypeInfo *tyinfo)
|
||||
dumpEnumType(fout, tyinfo);
|
||||
else if (tyinfo->typtype == TYPTYPE_RANGE)
|
||||
dumpRangeType(fout, tyinfo);
|
||||
else if (tyinfo->typtype == TYPTYPE_PSEUDO && !tyinfo->isDefined)
|
||||
dumpUndefinedType(fout, tyinfo);
|
||||
else
|
||||
write_msg(NULL, "WARNING: typtype of data type \"%s\" appears to be invalid\n",
|
||||
tyinfo->dobj.name);
|
||||
@@ -7783,6 +7781,73 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
|
||||
destroyPQExpBuffer(query);
|
||||
}
|
||||
|
||||
/*
|
||||
* dumpUndefinedType
|
||||
* writes out to fout the queries to recreate a !typisdefined type
|
||||
*
|
||||
* This is a shell type, but we use different terminology to distinguish
|
||||
* this case from where we have to emit a shell type definition to break
|
||||
* circular dependencies. An undefined type shouldn't ever have anything
|
||||
* depending on it.
|
||||
*/
|
||||
static void
|
||||
dumpUndefinedType(Archive *fout, TypeInfo *tyinfo)
|
||||
{
|
||||
PQExpBuffer q = createPQExpBuffer();
|
||||
PQExpBuffer delq = createPQExpBuffer();
|
||||
PQExpBuffer labelq = createPQExpBuffer();
|
||||
char *qtypname;
|
||||
|
||||
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
|
||||
|
||||
/*
|
||||
* DROP must be fully qualified in case same name appears in pg_catalog.
|
||||
*/
|
||||
appendPQExpBuffer(delq, "DROP TYPE %s.",
|
||||
fmtId(tyinfo->dobj.namespace->dobj.name));
|
||||
appendPQExpBuffer(delq, "%s;\n",
|
||||
qtypname);
|
||||
|
||||
if (binary_upgrade)
|
||||
binary_upgrade_set_type_oids_by_type_oid(fout,
|
||||
q, tyinfo->dobj.catId.oid);
|
||||
|
||||
appendPQExpBuffer(q, "CREATE TYPE %s;\n",
|
||||
qtypname);
|
||||
|
||||
appendPQExpBuffer(labelq, "TYPE %s", qtypname);
|
||||
|
||||
if (binary_upgrade)
|
||||
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
|
||||
|
||||
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
|
||||
tyinfo->dobj.name,
|
||||
tyinfo->dobj.namespace->dobj.name,
|
||||
NULL,
|
||||
tyinfo->rolname, false,
|
||||
"TYPE", SECTION_PRE_DATA,
|
||||
q->data, delq->data, NULL,
|
||||
NULL, 0,
|
||||
NULL, NULL);
|
||||
|
||||
/* Dump Type Comments and Security Labels */
|
||||
dumpComment(fout, labelq->data,
|
||||
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
|
||||
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
|
||||
dumpSecLabel(fout, labelq->data,
|
||||
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
|
||||
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
|
||||
|
||||
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
|
||||
qtypname, NULL, tyinfo->dobj.name,
|
||||
tyinfo->dobj.namespace->dobj.name,
|
||||
tyinfo->rolname, tyinfo->typacl);
|
||||
|
||||
destroyPQExpBuffer(q);
|
||||
destroyPQExpBuffer(delq);
|
||||
destroyPQExpBuffer(labelq);
|
||||
}
|
||||
|
||||
/*
|
||||
* dumpBaseType
|
||||
* writes out to fout the queries to recreate a user-defined base type
|
||||
|
Reference in New Issue
Block a user