Commit f3136467 authored by Tom Lane's avatar Tom Lane

Teach pg_dump to dump comments on RLS policy objects.

This was unaccountably omitted in the original RLS patch.
The SQL syntax is basically the same as for comments on triggers,
so crib code from dumpTrigger().

Per report from Marc Munro.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/1581889298.18009.15.camel@bloodnok.com
parent c6679e4f
...@@ -3666,6 +3666,8 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo) ...@@ -3666,6 +3666,8 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
TableInfo *tbinfo = polinfo->poltable; TableInfo *tbinfo = polinfo->poltable;
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer delqry; PQExpBuffer delqry;
PQExpBuffer polprefix;
char *qtabname;
const char *cmd; const char *cmd;
char *tag; char *tag;
...@@ -3723,6 +3725,9 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo) ...@@ -3723,6 +3725,9 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
query = createPQExpBuffer(); query = createPQExpBuffer();
delqry = createPQExpBuffer(); delqry = createPQExpBuffer();
polprefix = createPQExpBuffer();
qtabname = pg_strdup(fmtId(tbinfo->dobj.name));
appendPQExpBuffer(query, "CREATE POLICY %s", fmtId(polinfo->polname)); appendPQExpBuffer(query, "CREATE POLICY %s", fmtId(polinfo->polname));
...@@ -3743,6 +3748,9 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo) ...@@ -3743,6 +3748,9 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
appendPQExpBuffer(delqry, "DROP POLICY %s", fmtId(polinfo->polname)); appendPQExpBuffer(delqry, "DROP POLICY %s", fmtId(polinfo->polname));
appendPQExpBuffer(delqry, " ON %s;\n", fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(delqry, " ON %s;\n", fmtQualifiedDumpable(tbinfo));
appendPQExpBuffer(polprefix, "POLICY %s ON",
fmtId(polinfo->polname));
tag = psprintf("%s %s", tbinfo->dobj.name, polinfo->dobj.name); tag = psprintf("%s %s", tbinfo->dobj.name, polinfo->dobj.name);
if (polinfo->dobj.dump & DUMP_COMPONENT_POLICY) if (polinfo->dobj.dump & DUMP_COMPONENT_POLICY)
...@@ -3755,9 +3763,16 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo) ...@@ -3755,9 +3763,16 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
.createStmt = query->data, .createStmt = query->data,
.dropStmt = delqry->data)); .dropStmt = delqry->data));
if (polinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, polprefix->data, qtabname,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
polinfo->dobj.catId, 0, polinfo->dobj.dumpId);
free(tag); free(tag);
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry); destroyPQExpBuffer(delqry);
destroyPQExpBuffer(polprefix);
free(qtabname);
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment