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

Commit cf615fb

Browse files
committed
pg_dump: Dump comments and security labels for publication and subscriptions
1 parent d04eac1 commit cf615fb

File tree

2 files changed

+128
-16
lines changed

2 files changed

+128
-16
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3456,19 +3456,23 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo)
34563456
{
34573457
PQExpBuffer delq;
34583458
PQExpBuffer query;
3459+
PQExpBuffer labelq;
34593460

34603461
if (!(pubinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
34613462
return;
34623463

34633464
delq = createPQExpBuffer();
34643465
query = createPQExpBuffer();
3466+
labelq = createPQExpBuffer();
34653467

34663468
appendPQExpBuffer(delq, "DROP PUBLICATION %s;\n",
34673469
fmtId(pubinfo->dobj.name));
34683470

34693471
appendPQExpBuffer(query, "CREATE PUBLICATION %s",
34703472
fmtId(pubinfo->dobj.name));
34713473

3474+
appendPQExpBuffer(labelq, "PUBLICATION %s", fmtId(pubinfo->dobj.name));
3475+
34723476
if (pubinfo->puballtables)
34733477
appendPQExpBufferStr(query, " FOR ALL TABLES");
34743478

@@ -3500,6 +3504,16 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo)
35003504
NULL, 0,
35013505
NULL, NULL);
35023506

3507+
if (pubinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3508+
dumpComment(fout, labelq->data,
3509+
NULL, pubinfo->rolname,
3510+
pubinfo->dobj.catId, 0, pubinfo->dobj.dumpId);
3511+
3512+
if (pubinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3513+
dumpSecLabel(fout, labelq->data,
3514+
NULL, pubinfo->rolname,
3515+
pubinfo->dobj.catId, 0, pubinfo->dobj.dumpId);
3516+
35033517
destroyPQExpBuffer(delq);
35043518
destroyPQExpBuffer(query);
35053519
}
@@ -3754,6 +3768,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
37543768
{
37553769
PQExpBuffer delq;
37563770
PQExpBuffer query;
3771+
PQExpBuffer labelq;
37573772
PQExpBuffer publications;
37583773
char **pubnames = NULL;
37593774
int npubnames = 0;
@@ -3764,6 +3779,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
37643779

37653780
delq = createPQExpBuffer();
37663781
query = createPQExpBuffer();
3782+
labelq = createPQExpBuffer();
37673783

37683784
appendPQExpBuffer(delq, "DROP SUBSCRIPTION %s;\n",
37693785
fmtId(subinfo->dobj.name));
@@ -3796,6 +3812,8 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
37963812
appendStringLiteralAH(query, subinfo->subslotname, fout);
37973813
appendPQExpBufferStr(query, ");\n");
37983814

3815+
appendPQExpBuffer(labelq, "SUBSCRIPTION %s", fmtId(subinfo->dobj.name));
3816+
37993817
ArchiveEntry(fout, subinfo->dobj.catId, subinfo->dobj.dumpId,
38003818
subinfo->dobj.name,
38013819
NULL,
@@ -3806,6 +3824,16 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
38063824
NULL, 0,
38073825
NULL, NULL);
38083826

3827+
if (subinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3828+
dumpComment(fout, labelq->data,
3829+
NULL, subinfo->rolname,
3830+
subinfo->dobj.catId, 0, subinfo->dobj.dumpId);
3831+
3832+
if (subinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3833+
dumpSecLabel(fout, labelq->data,
3834+
NULL, subinfo->rolname,
3835+
subinfo->dobj.catId, 0, subinfo->dobj.dumpId);
3836+
38093837
destroyPQExpBuffer(publications);
38103838
if (pubnames)
38113839
free(pubnames);

src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 100 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,7 @@
15171517
only_dump_test_schema => 1,
15181518
only_dump_test_table => 1,
15191519
role => 1,
1520+
section_post_data => 1,
15201521
test_schema_plus_blobs => 1, }, },
15211522

15221523
'COMMENT ON EXTENSION plpgsql' => {
@@ -1545,6 +1546,7 @@
15451546
only_dump_test_schema => 1,
15461547
only_dump_test_table => 1,
15471548
role => 1,
1549+
section_post_data => 1,
15481550
test_schema_plus_blobs => 1, }, },
15491551

15501552
'COMMENT ON TABLE dump_test.test_table' => {
@@ -1576,7 +1578,8 @@
15761578
data_only => 1,
15771579
exclude_dump_test_schema => 1,
15781580
exclude_test_table => 1,
1579-
role => 1, }, },
1581+
role => 1,
1582+
section_post_data => 1, }, },
15801583

15811584
'COMMENT ON COLUMN dump_test.test_table.col1' => {
15821585
all_runs => 1,
@@ -1609,7 +1612,8 @@
16091612
data_only => 1,
16101613
exclude_dump_test_schema => 1,
16111614
exclude_test_table => 1,
1612-
role => 1, }, },
1615+
role => 1,
1616+
section_post_data => 1, }, },
16131617

16141618
'COMMENT ON COLUMN dump_test.composite.f1' => {
16151619
all_runs => 1,
@@ -1642,7 +1646,8 @@
16421646
data_only => 1,
16431647
exclude_dump_test_schema => 1,
16441648
only_dump_test_table => 1,
1645-
role => 1, }, },
1649+
role => 1,
1650+
section_post_data => 1, }, },
16461651

16471652
'COMMENT ON COLUMN dump_test.test_second_table.col1' => {
16481653
all_runs => 1,
@@ -1675,7 +1680,8 @@
16751680
data_only => 1,
16761681
exclude_dump_test_schema => 1,
16771682
only_dump_test_table => 1,
1678-
role => 1, }, },
1683+
role => 1,
1684+
section_post_data => 1, }, },
16791685

16801686
'COMMENT ON COLUMN dump_test.test_second_table.col2' => {
16811687
all_runs => 1,
@@ -1708,7 +1714,8 @@
17081714
data_only => 1,
17091715
exclude_dump_test_schema => 1,
17101716
only_dump_test_table => 1,
1711-
role => 1, }, },
1717+
role => 1,
1718+
section_post_data => 1, }, },
17121719

17131720
'COMMENT ON CONVERSION dump_test.test_conversion' => {
17141721
all_runs => 1,
@@ -1739,7 +1746,8 @@
17391746
data_only => 1,
17401747
exclude_dump_test_schema => 1,
17411748
only_dump_test_table => 1,
1742-
role => 1, }, },
1749+
role => 1,
1750+
section_post_data => 1, }, },
17431751

17441752
'COMMENT ON COLLATION test0' => {
17451753
all_runs => 1,
@@ -1771,6 +1779,7 @@
17711779
only_dump_test_schema => 1,
17721780
only_dump_test_table => 1,
17731781
role => 1,
1782+
section_post_data => 1,
17741783
test_schema_plus_blobs => 1, }, },
17751784

17761785
'COMMENT ON LARGE OBJECT ...' => {
@@ -1814,6 +1823,74 @@
18141823
section_data => 1,
18151824
section_post_data => 1, }, },
18161825

1826+
'COMMENT ON PUBLICATION pub1' => {
1827+
all_runs => 1,
1828+
create_order => 55,
1829+
create_sql => 'COMMENT ON PUBLICATION pub1
1830+
IS \'comment on publication\';',
1831+
regexp => qr/^COMMENT ON PUBLICATION pub1 IS 'comment on publication';/m,
1832+
like => {
1833+
binary_upgrade => 1,
1834+
clean => 1,
1835+
clean_if_exists => 1,
1836+
createdb => 1,
1837+
defaults => 1,
1838+
exclude_dump_test_schema => 1,
1839+
exclude_test_table => 1,
1840+
exclude_test_table_data => 1,
1841+
no_blobs => 1,
1842+
no_privs => 1,
1843+
no_owner => 1,
1844+
pg_dumpall_dbprivs => 1,
1845+
schema_only => 1,
1846+
section_post_data => 1,
1847+
with_oids => 1, },
1848+
unlike => {
1849+
column_inserts => 1,
1850+
data_only => 1,
1851+
only_dump_test_table => 1,
1852+
only_dump_test_schema => 1,
1853+
pg_dumpall_globals => 1,
1854+
pg_dumpall_globals_clean => 1,
1855+
role => 1,
1856+
section_data => 1,
1857+
section_pre_data => 1,
1858+
test_schema_plus_blobs => 1, }, },
1859+
1860+
'COMMENT ON SUBSCRIPTION sub1' => {
1861+
all_runs => 1,
1862+
create_order => 55,
1863+
create_sql => 'COMMENT ON SUBSCRIPTION sub1
1864+
IS \'comment on subscription\';',
1865+
regexp => qr/^COMMENT ON SUBSCRIPTION sub1 IS 'comment on subscription';/m,
1866+
like => {
1867+
binary_upgrade => 1,
1868+
clean => 1,
1869+
clean_if_exists => 1,
1870+
createdb => 1,
1871+
defaults => 1,
1872+
exclude_dump_test_schema => 1,
1873+
exclude_test_table => 1,
1874+
exclude_test_table_data => 1,
1875+
no_blobs => 1,
1876+
no_privs => 1,
1877+
no_owner => 1,
1878+
pg_dumpall_dbprivs => 1,
1879+
schema_only => 1,
1880+
section_post_data => 1,
1881+
with_oids => 1, },
1882+
unlike => {
1883+
column_inserts => 1,
1884+
data_only => 1,
1885+
only_dump_test_table => 1,
1886+
only_dump_test_schema => 1,
1887+
pg_dumpall_globals => 1,
1888+
pg_dumpall_globals_clean => 1,
1889+
role => 1,
1890+
section_data => 1,
1891+
section_pre_data => 1,
1892+
test_schema_plus_blobs => 1, }, },
1893+
18171894
'COMMENT ON TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1' => {
18181895
all_runs => 1,
18191896
catch_all => 'COMMENT commands',
@@ -1843,7 +1920,8 @@
18431920
data_only => 1,
18441921
exclude_dump_test_schema => 1,
18451922
only_dump_test_table => 1,
1846-
role => 1, }, },
1923+
role => 1,
1924+
section_post_data => 1, }, },
18471925

18481926
'COMMENT ON TEXT SEARCH DICTIONARY dump_test.alt_ts_dict1' => {
18491927
all_runs => 1,
@@ -1874,7 +1952,8 @@
18741952
data_only => 1,
18751953
exclude_dump_test_schema => 1,
18761954
only_dump_test_table => 1,
1877-
role => 1, }, },
1955+
role => 1,
1956+
section_post_data => 1, }, },
18781957

18791958
'COMMENT ON TEXT SEARCH PARSER dump_test.alt_ts_prs1' => {
18801959
all_runs => 1,
@@ -1905,7 +1984,8 @@
19051984
data_only => 1,
19061985
exclude_dump_test_schema => 1,
19071986
only_dump_test_table => 1,
1908-
role => 1, }, },
1987+
role => 1,
1988+
section_post_data => 1, }, },
19091989

19101990
'COMMENT ON TEXT SEARCH TEMPLATE dump_test.alt_ts_temp1' => {
19111991
all_runs => 1,
@@ -1936,7 +2016,8 @@
19362016
data_only => 1,
19372017
exclude_dump_test_schema => 1,
19382018
only_dump_test_table => 1,
1939-
role => 1, }, },
2019+
role => 1,
2020+
section_post_data => 1, }, },
19402021

19412022
'COMMENT ON TYPE dump_test.planets - ENUM' => {
19422023
all_runs => 1,
@@ -1967,7 +2048,8 @@
19672048
data_only => 1,
19682049
exclude_dump_test_schema => 1,
19692050
only_dump_test_table => 1,
1970-
role => 1, }, },
2051+
role => 1,
2052+
section_post_data => 1, }, },
19712053

19722054
'COMMENT ON TYPE dump_test.textrange - RANGE' => {
19732055
all_runs => 1,
@@ -1998,7 +2080,8 @@
19982080
data_only => 1,
19992081
exclude_dump_test_schema => 1,
20002082
only_dump_test_table => 1,
2001-
role => 1, }, },
2083+
role => 1,
2084+
section_post_data => 1, }, },
20022085

20032086
'COMMENT ON TYPE dump_test.int42 - Regular' => {
20042087
all_runs => 1,
@@ -2029,7 +2112,8 @@
20292112
data_only => 1,
20302113
exclude_dump_test_schema => 1,
20312114
only_dump_test_table => 1,
2032-
role => 1, }, },
2115+
role => 1,
2116+
section_post_data => 1, }, },
20332117

20342118
'COMMENT ON TYPE dump_test.undefined - Undefined' => {
20352119
all_runs => 1,
@@ -2060,7 +2144,8 @@
20602144
data_only => 1,
20612145
exclude_dump_test_schema => 1,
20622146
only_dump_test_table => 1,
2063-
role => 1, }, },
2147+
role => 1,
2148+
section_post_data => 1, }, },
20642149

20652150
# catch-all for COMMENTs
20662151
'COMMENT commands' => {
@@ -2070,8 +2155,7 @@
20702155
unlike => {
20712156
pg_dumpall_globals => 1,
20722157
pg_dumpall_globals_clean => 1,
2073-
section_data => 1,
2074-
section_post_data => 1, }, },
2158+
section_data => 1, }, },
20752159

20762160
'COPY test_table' => {
20772161
all_runs => 1,

0 commit comments

Comments
 (0)