]> granicus.if.org Git - postgresql/commitdiff
pg_dump: Dump comments and security labels for publication and subscriptions
authorPeter Eisentraut <peter_e@gmx.net>
Fri, 14 Apr 2017 02:32:03 +0000 (22:32 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 14 Apr 2017 02:46:17 +0000 (22:46 -0400)
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/t/002_pg_dump.pl

index 14dc1b242320bea1f1324897181057b133aba1d1..58566f423f57fe8cd6ebdf28a2e8d4b560385c52 100644 (file)
@@ -3456,12 +3456,14 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo)
 {
        PQExpBuffer delq;
        PQExpBuffer query;
+       PQExpBuffer labelq;
 
        if (!(pubinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
                return;
 
        delq = createPQExpBuffer();
        query = createPQExpBuffer();
+       labelq = createPQExpBuffer();
 
        appendPQExpBuffer(delq, "DROP PUBLICATION %s;\n",
                                          fmtId(pubinfo->dobj.name));
@@ -3469,6 +3471,8 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo)
        appendPQExpBuffer(query, "CREATE PUBLICATION %s",
                                          fmtId(pubinfo->dobj.name));
 
+       appendPQExpBuffer(labelq, "PUBLICATION %s", fmtId(pubinfo->dobj.name));
+
        if (pubinfo->puballtables)
                appendPQExpBufferStr(query, " FOR ALL TABLES");
 
@@ -3500,6 +3504,16 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo)
                                 NULL, 0,
                                 NULL, NULL);
 
+       if (pubinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
+               dumpComment(fout, labelq->data,
+                                       NULL, pubinfo->rolname,
+                                       pubinfo->dobj.catId, 0, pubinfo->dobj.dumpId);
+
+       if (pubinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
+               dumpSecLabel(fout, labelq->data,
+                                        NULL, pubinfo->rolname,
+                                        pubinfo->dobj.catId, 0, pubinfo->dobj.dumpId);
+
        destroyPQExpBuffer(delq);
        destroyPQExpBuffer(query);
 }
@@ -3754,6 +3768,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
 {
        PQExpBuffer delq;
        PQExpBuffer query;
+       PQExpBuffer labelq;
        PQExpBuffer publications;
        char      **pubnames = NULL;
        int                     npubnames = 0;
@@ -3764,6 +3779,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
 
        delq = createPQExpBuffer();
        query = createPQExpBuffer();
+       labelq = createPQExpBuffer();
 
        appendPQExpBuffer(delq, "DROP SUBSCRIPTION %s;\n",
                                          fmtId(subinfo->dobj.name));
@@ -3796,6 +3812,8 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
        appendStringLiteralAH(query, subinfo->subslotname, fout);
        appendPQExpBufferStr(query, ");\n");
 
+       appendPQExpBuffer(labelq, "SUBSCRIPTION %s", fmtId(subinfo->dobj.name));
+
        ArchiveEntry(fout, subinfo->dobj.catId, subinfo->dobj.dumpId,
                                 subinfo->dobj.name,
                                 NULL,
@@ -3806,6 +3824,16 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
                                 NULL, 0,
                                 NULL, NULL);
 
+       if (subinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
+               dumpComment(fout, labelq->data,
+                                       NULL, subinfo->rolname,
+                                       subinfo->dobj.catId, 0, subinfo->dobj.dumpId);
+
+       if (subinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
+               dumpSecLabel(fout, labelq->data,
+                                        NULL, subinfo->rolname,
+                                        subinfo->dobj.catId, 0, subinfo->dobj.dumpId);
+
        destroyPQExpBuffer(publications);
        if (pubnames)
                free(pubnames);
index e0d1ce62323df88b2e383be5927620b5eb3fb529..4dd208e8e1111978504d09a61b84b79106a54bc5 100644 (file)
@@ -1517,6 +1517,7 @@ my %tests = (
                        only_dump_test_schema  => 1,
                        only_dump_test_table   => 1,
                        role                   => 1,
+                       section_post_data       => 1,
                        test_schema_plus_blobs => 1, }, },
 
        'COMMENT ON EXTENSION plpgsql' => {
@@ -1545,6 +1546,7 @@ my %tests = (
                        only_dump_test_schema  => 1,
                        only_dump_test_table   => 1,
                        role                   => 1,
+                       section_post_data       => 1,
                        test_schema_plus_blobs => 1, }, },
 
        'COMMENT ON TABLE dump_test.test_table' => {
@@ -1576,7 +1578,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        exclude_test_table       => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON COLUMN dump_test.test_table.col1' => {
                all_runs     => 1,
@@ -1609,7 +1612,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        exclude_test_table       => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON COLUMN dump_test.composite.f1' => {
                all_runs     => 1,
@@ -1642,7 +1646,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON COLUMN dump_test.test_second_table.col1' => {
                all_runs     => 1,
@@ -1675,7 +1680,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON COLUMN dump_test.test_second_table.col2' => {
                all_runs     => 1,
@@ -1708,7 +1714,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON CONVERSION dump_test.test_conversion' => {
                all_runs     => 1,
@@ -1739,7 +1746,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON COLLATION test0' => {
                all_runs     => 1,
@@ -1771,6 +1779,7 @@ my %tests = (
                        only_dump_test_schema  => 1,
                        only_dump_test_table   => 1,
                        role                   => 1,
+                       section_post_data      => 1,
                        test_schema_plus_blobs => 1, }, },
 
        'COMMENT ON LARGE OBJECT ...' => {
@@ -1814,6 +1823,74 @@ my %tests = (
                        section_data             => 1,
                        section_post_data        => 1, }, },
 
+       'COMMENT ON PUBLICATION pub1' => {
+               all_runs     => 1,
+               create_order => 55,
+               create_sql   => 'COMMENT ON PUBLICATION pub1
+                                          IS \'comment on publication\';',
+               regexp => qr/^COMMENT ON PUBLICATION pub1 IS 'comment on publication';/m,
+               like   => {
+                       binary_upgrade           => 1,
+                       clean                    => 1,
+                       clean_if_exists          => 1,
+                       createdb                 => 1,
+                       defaults                 => 1,
+                       exclude_dump_test_schema => 1,
+                       exclude_test_table       => 1,
+                       exclude_test_table_data  => 1,
+                       no_blobs                 => 1,
+                       no_privs                 => 1,
+                       no_owner                 => 1,
+                       pg_dumpall_dbprivs       => 1,
+                       schema_only              => 1,
+                       section_post_data        => 1,
+                       with_oids                => 1, },
+               unlike => {
+                       column_inserts           => 1,
+                       data_only                => 1,
+                       only_dump_test_table     => 1,
+                       only_dump_test_schema    => 1,
+                       pg_dumpall_globals       => 1,
+                       pg_dumpall_globals_clean => 1,
+                       role                     => 1,
+                       section_data             => 1,
+                       section_pre_data         => 1,
+                       test_schema_plus_blobs   => 1, }, },
+
+       'COMMENT ON SUBSCRIPTION sub1' => {
+               all_runs     => 1,
+               create_order => 55,
+               create_sql   => 'COMMENT ON SUBSCRIPTION sub1
+                                          IS \'comment on subscription\';',
+               regexp => qr/^COMMENT ON SUBSCRIPTION sub1 IS 'comment on subscription';/m,
+               like   => {
+                       binary_upgrade           => 1,
+                       clean                    => 1,
+                       clean_if_exists          => 1,
+                       createdb                 => 1,
+                       defaults                 => 1,
+                       exclude_dump_test_schema => 1,
+                       exclude_test_table       => 1,
+                       exclude_test_table_data  => 1,
+                       no_blobs                 => 1,
+                       no_privs                 => 1,
+                       no_owner                 => 1,
+                       pg_dumpall_dbprivs       => 1,
+                       schema_only              => 1,
+                       section_post_data        => 1,
+                       with_oids                => 1, },
+               unlike => {
+                       column_inserts           => 1,
+                       data_only                => 1,
+                       only_dump_test_table     => 1,
+                       only_dump_test_schema    => 1,
+                       pg_dumpall_globals       => 1,
+                       pg_dumpall_globals_clean => 1,
+                       role                     => 1,
+                       section_data             => 1,
+                       section_pre_data         => 1,
+                       test_schema_plus_blobs   => 1, }, },
+
        'COMMENT ON TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1' => {
                all_runs     => 1,
                catch_all    => 'COMMENT commands',
@@ -1843,7 +1920,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON TEXT SEARCH DICTIONARY dump_test.alt_ts_dict1' => {
                all_runs     => 1,
@@ -1874,7 +1952,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON TEXT SEARCH PARSER dump_test.alt_ts_prs1' => {
                all_runs     => 1,
@@ -1905,7 +1984,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON TEXT SEARCH TEMPLATE dump_test.alt_ts_temp1' => {
                all_runs     => 1,
@@ -1936,7 +2016,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON TYPE dump_test.planets - ENUM' => {
                all_runs     => 1,
@@ -1967,7 +2048,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON TYPE dump_test.textrange - RANGE' => {
                all_runs     => 1,
@@ -1998,7 +2080,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table    => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON TYPE dump_test.int42 - Regular' => {
                all_runs     => 1,
@@ -2029,7 +2112,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        'COMMENT ON TYPE dump_test.undefined - Undefined' => {
                all_runs     => 1,
@@ -2060,7 +2144,8 @@ my %tests = (
                        data_only                => 1,
                        exclude_dump_test_schema => 1,
                        only_dump_test_table     => 1,
-                       role                     => 1, }, },
+                       role                     => 1,
+                       section_post_data        => 1, }, },
 
        # catch-all for COMMENTs
        'COMMENT commands' => {
@@ -2070,8 +2155,7 @@ my %tests = (
                unlike   => {
                        pg_dumpall_globals       => 1,
                        pg_dumpall_globals_clean => 1,
-                       section_data             => 1,
-                       section_post_data        => 1, }, },
+                       section_data             => 1, }, },
 
        'COPY test_table' => {
                all_runs     => 1,