Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 576856b

Browse files
committed
Dump comments on columns of composite types.
Instead of putting all the OWNER TO commands at the end, it dumps then after each object. This is WAY more readable and nice. ACLs are still at the end. Christopher Kings-Lynne
1 parent 6568d64 commit 576856b

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

src/bin/pg_dump/pg_backup_archiver.c

+28-28
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.90 2004/07/19 21:39:47 momjian Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.91 2004/08/04 17:13:03 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -49,7 +49,7 @@ static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
4949
const int compression, ArchiveMode mode);
5050
static char *_getObjectFromDropStmt(const char *dropStmt, const char *type);
5151
static void _printTocHeader(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData);
52-
static int _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData, bool ownerAndACL);
52+
static int _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData, bool acl_pass);
5353

5454

5555
static void fixPriorBlobRefs(ArchiveHandle *AH, TocEntry *blobte,
@@ -62,7 +62,7 @@ static void _becomeUser(ArchiveHandle *AH, const char *user);
6262
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
6363
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName);
6464

65-
static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool ownerAndACL);
65+
static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool acl_pass);
6666
static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
6767
static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
6868
static TocEntry *getTocEntryByDumpId(ArchiveHandle *AH, DumpId id);
@@ -1913,7 +1913,7 @@ ReadToc(ArchiveHandle *AH)
19131913
}
19141914

19151915
static teReqs
1916-
_tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool ownerAndACL)
1916+
_tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool acl_pass)
19171917
{
19181918
teReqs res = 3; /* Schema = 1, Data = 2, Both = 3 */
19191919

@@ -1922,7 +1922,7 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool ownerAndACL)
19221922
return 0;
19231923

19241924
/* If it's an ACL, maybe ignore it */
1925-
if ((!ownerAndACL || ropt->aclsSkip) && strcmp(te->desc, "ACL") == 0)
1925+
if ((!acl_pass || ropt->aclsSkip) && strcmp(te->desc, "ACL") == 0)
19261926
return 0;
19271927

19281928
if (!ropt->create && strcmp(te->desc, "DATABASE") == 0)
@@ -2338,39 +2338,20 @@ _printTocHeader(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDa
23382338
}
23392339

23402340
static int
2341-
_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData, bool ownerAndACL)
2341+
_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData, bool acl_pass)
23422342
{
23432343
/* Select schema as necessary */
23442344
_becomeOwner(AH, te);
23452345
_selectOutputSchema(AH, te->namespace);
2346-
if (strcmp(te->desc, "TABLE") == 0 && !ownerAndACL)
2346+
if (strcmp(te->desc, "TABLE") == 0 && !acl_pass)
23472347
_setWithOids(AH, te);
23482348

2349-
if (!ropt->noOwner && !ropt->use_setsessauth && ownerAndACL && strlen(te->owner) > 0 && strlen(te->dropStmt) > 0 && (
2350-
strcmp(te->desc, "AGGREGATE") == 0 ||
2351-
strcmp(te->desc, "CONVERSION") == 0 ||
2352-
strcmp(te->desc, "DOMAIN") == 0 ||
2353-
strcmp(te->desc, "FUNCTION") == 0 ||
2354-
strcmp(te->desc, "OPERATOR") == 0 ||
2355-
strcmp(te->desc, "OPERATOR CLASS") == 0 ||
2356-
strcmp(te->desc, "TABLE") == 0 ||
2357-
strcmp(te->desc, "TYPE") == 0 ||
2358-
strcmp(te->desc, "VIEW") == 0 ||
2359-
strcmp(te->desc, "SEQUENCE") == 0 ||
2360-
(strcmp(te->desc, "SCHEMA") == 0 && strcmp(te->tag, "public") == 0) /* Only public schema */
2361-
))
2362-
{
2363-
char *temp = _getObjectFromDropStmt(te->dropStmt, te->desc);
2364-
_printTocHeader(AH, te, ropt, isData);
2365-
ahprintf(AH, "ALTER %s OWNER TO %s;\n\n", temp, fmtId(te->owner));
2366-
free (temp);
2367-
}
2368-
else if (ownerAndACL && strcmp(te->desc, "ACL") == 0)
2349+
if (acl_pass && strcmp(te->desc, "ACL") == 0)
23692350
{
23702351
_printTocHeader(AH, te, ropt, isData);
23712352
ahprintf(AH, "%s\n\n", te->defn);
23722353
}
2373-
else if (!ownerAndACL && strlen(te->defn) > 0)
2354+
else if (!acl_pass && strlen(te->defn) > 0)
23742355
{
23752356
_printTocHeader(AH, te, ropt, isData);
23762357

@@ -2388,6 +2369,25 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
23882369
else
23892370
{
23902371
ahprintf(AH, "%s\n\n", te->defn);
2372+
2373+
if (!ropt->noOwner && !ropt->use_setsessauth && strlen(te->owner) > 0 && strlen(te->dropStmt) > 0 && (
2374+
strcmp(te->desc, "AGGREGATE") == 0 ||
2375+
strcmp(te->desc, "CONVERSION") == 0 ||
2376+
strcmp(te->desc, "DOMAIN") == 0 ||
2377+
strcmp(te->desc, "FUNCTION") == 0 ||
2378+
strcmp(te->desc, "OPERATOR") == 0 ||
2379+
strcmp(te->desc, "OPERATOR CLASS") == 0 ||
2380+
strcmp(te->desc, "TABLE") == 0 ||
2381+
strcmp(te->desc, "TYPE") == 0 ||
2382+
strcmp(te->desc, "VIEW") == 0 ||
2383+
strcmp(te->desc, "SEQUENCE") == 0 ||
2384+
(strcmp(te->desc, "SCHEMA") == 0 && strcmp(te->tag, "public") == 0) /* Only public schema */
2385+
))
2386+
{
2387+
char *temp = _getObjectFromDropStmt(te->dropStmt, te->desc);
2388+
ahprintf(AH, "ALTER %s OWNER TO %s;\n\n", temp, fmtId(te->owner));
2389+
free (temp);
2390+
}
23912391
}
23922392
}
23932393
}

src/bin/pg_dump/pg_dump.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.381 2004/08/02 04:28:03 tgl Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.382 2004/08/04 17:13:03 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -2393,10 +2393,10 @@ getTables(int *numTables)
23932393
"d.classid = c.tableoid and d.objid = c.oid and "
23942394
"d.objsubid = 0 and "
23952395
"d.refclassid = c.tableoid and d.deptype = 'i') "
2396-
"where relkind in ('%c', '%c', '%c') "
2396+
"where relkind in ('%c', '%c', '%c', '%c') "
23972397
"order by c.oid",
23982398
RELKIND_SEQUENCE,
2399-
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
2399+
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
24002400
}
24012401
else if (g_fout->remoteVersion >= 70300)
24022402
{
@@ -2419,10 +2419,10 @@ getTables(int *numTables)
24192419
"d.classid = c.tableoid and d.objid = c.oid and "
24202420
"d.objsubid = 0 and "
24212421
"d.refclassid = c.tableoid and d.deptype = 'i') "
2422-
"where relkind in ('%c', '%c', '%c') "
2422+
"where relkind in ('%c', '%c', '%c', '%c') "
24232423
"order by c.oid",
24242424
RELKIND_SEQUENCE,
2425-
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
2425+
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
24262426
}
24272427
else if (g_fout->remoteVersion >= 70200)
24282428
{
@@ -4063,7 +4063,7 @@ dumpComment(Archive *fout, const char *target,
40634063
/*
40644064
* dumpTableComment --
40654065
*
4066-
* As above, but dump comments for both the specified table (or view)
4066+
* As above, but dump comments for both the specified table, view or composite type
40674067
* and its columns.
40684068
*/
40694069
static void
@@ -4864,6 +4864,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tinfo)
48644864
int i_attname;
48654865
int i_atttypdefn;
48664866
int i;
4867+
TableInfo *tableInfo;
48674868

48684869
/* Set proper schema search path so type references list correctly */
48694870
selectSourceSchema(tinfo->dobj.namespace->dobj.name);
@@ -4928,7 +4929,6 @@ dumpCompositeType(Archive *fout, TypeInfo *tinfo)
49284929
tinfo->dobj.dependencies, tinfo->dobj.nDeps,
49294930
NULL, NULL);
49304931

4931-
49324932
/* Dump Type Comments */
49334933
resetPQExpBuffer(q);
49344934

@@ -4937,7 +4937,13 @@ dumpCompositeType(Archive *fout, TypeInfo *tinfo)
49374937
tinfo->dobj.namespace->dobj.name, tinfo->usename,
49384938
tinfo->dobj.catId, 0, tinfo->dobj.dumpId);
49394939

4940+
/* Dump column comments */
4941+
tableInfo = findTableByOid(tinfo->typrelid);
4942+
if (tableInfo)
4943+
dumpTableComment(fout, tableInfo, "TABLE");
4944+
49404945
PQclear(res);
4946+
49414947
destroyPQExpBuffer(q);
49424948
destroyPQExpBuffer(delq);
49434949
destroyPQExpBuffer(query);
@@ -6432,7 +6438,7 @@ dumpTable(Archive *fout, TableInfo *tbinfo)
64326438
{
64336439
if (tbinfo->relkind == RELKIND_SEQUENCE)
64346440
dumpSequence(fout, tbinfo);
6435-
else if (!dataOnly)
6441+
else if (!dataOnly && tbinfo->relkind != RELKIND_COMPOSITE_TYPE)
64366442
dumpTableSchema(fout, tbinfo);
64376443

64386444
/* Handle the ACL here */

0 commit comments

Comments
 (0)