|
3 | 3 | use warnings;
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::More tests => 16; |
| 6 | +use Test::More tests => 19; |
7 | 7 |
|
8 | 8 | # Initialize publisher node
|
9 | 9 | my $node_publisher = get_new_node('publisher');
|
|
28 | 28 | $node_publisher->safe_psql('postgres',
|
29 | 29 | "CREATE TABLE tab_rep (a int primary key)");
|
30 | 30 | $node_publisher->safe_psql('postgres',
|
31 |
| - "CREATE TABLE tab_mixed (a int primary key, b text)"); |
| 31 | + "CREATE TABLE tab_mixed (a int primary key, b text, c numeric)"); |
32 | 32 | $node_publisher->safe_psql('postgres',
|
33 |
| - "INSERT INTO tab_mixed (a, b) VALUES (1, 'foo')"); |
| 33 | + "INSERT INTO tab_mixed (a, b, c) VALUES (1, 'foo', 1.1)"); |
34 | 34 |
|
35 | 35 | # Setup structure on subscriber
|
36 | 36 | $node_subscriber->safe_psql('postgres', "CREATE TABLE tab_notrep (a int)");
|
|
42 | 42 |
|
43 | 43 | # different column count and order than on publisher
|
44 | 44 | $node_subscriber->safe_psql('postgres',
|
45 |
| - "CREATE TABLE tab_mixed (c text, b text, a int primary key)"); |
| 45 | + "CREATE TABLE tab_mixed (d text default 'local', c numeric, b text, a int primary key)" |
| 46 | +); |
46 | 47 |
|
47 | 48 | # Setup logical replication
|
48 | 49 | my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
|
|
91 | 92 | $node_publisher->safe_psql('postgres', "UPDATE tab_rep SET a = -a");
|
92 | 93 |
|
93 | 94 | $node_publisher->safe_psql('postgres',
|
94 |
| - "INSERT INTO tab_mixed VALUES (2, 'bar')"); |
| 95 | + "INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)"); |
95 | 96 |
|
96 | 97 | $node_publisher->poll_query_until('postgres', $caughtup_query)
|
97 | 98 | or die "Timed out while waiting for subscriber to catch up";
|
|
104 | 105 | "SELECT count(*), min(a), max(a) FROM tab_rep");
|
105 | 106 | is($result, qq(20|-20|-1), 'check replicated changes on subscriber');
|
106 | 107 |
|
107 |
| -$result = |
108 |
| - $node_subscriber->safe_psql('postgres', "SELECT c, b, a FROM tab_mixed"); |
109 |
| -is( $result, qq(|foo|1 |
110 |
| -|bar|2), 'check replicated changes with different column order'); |
| 108 | +$result = $node_subscriber->safe_psql('postgres', "SELECT * FROM tab_mixed"); |
| 109 | +is( $result, qq(local|1.1|foo|1 |
| 110 | +local|2.2|bar|2), 'check replicated changes with different column order'); |
111 | 111 |
|
112 | 112 | # insert some duplicate rows
|
113 | 113 | $node_publisher->safe_psql('postgres',
|
|
126 | 126 | "ALTER TABLE tab_ins REPLICA IDENTITY FULL");
|
127 | 127 | $node_subscriber->safe_psql('postgres',
|
128 | 128 | "ALTER TABLE tab_ins REPLICA IDENTITY FULL");
|
| 129 | +# tab_mixed can use DEFAULT, since it has a primary key |
129 | 130 |
|
130 | 131 | # and do the updates
|
131 | 132 | $node_publisher->safe_psql('postgres', "UPDATE tab_full SET a = a * a");
|
132 | 133 | $node_publisher->safe_psql('postgres',
|
133 | 134 | "UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'");
|
| 135 | +$node_publisher->safe_psql('postgres', |
| 136 | + "UPDATE tab_mixed SET b = 'baz' WHERE a = 1"); |
134 | 137 |
|
135 | 138 | # Wait for subscription to catch up
|
136 | 139 | $node_publisher->poll_query_until('postgres', $caughtup_query)
|
|
148 | 151 | bb),
|
149 | 152 | 'update works with REPLICA IDENTITY FULL and text datums');
|
150 | 153 |
|
| 154 | +$result = $node_subscriber->safe_psql('postgres', |
| 155 | + "SELECT * FROM tab_mixed ORDER BY a"); |
| 156 | +is( $result, qq(local|1.1|baz|1 |
| 157 | +local|2.2|bar|2), |
| 158 | + 'update works with different column order and subscriber local values'); |
| 159 | + |
| 160 | +# check behavior with dropped columns |
| 161 | + |
| 162 | +$node_publisher->safe_psql('postgres', "ALTER TABLE tab_mixed DROP COLUMN b"); |
| 163 | +$node_publisher->safe_psql('postgres', |
| 164 | + "UPDATE tab_mixed SET c = 11.11 WHERE a = 1"); |
| 165 | + |
| 166 | +$node_publisher->poll_query_until('postgres', $caughtup_query) |
| 167 | + or die "Timed out while waiting for subscriber to catch up"; |
| 168 | + |
| 169 | +$result = $node_subscriber->safe_psql('postgres', |
| 170 | + "SELECT * FROM tab_mixed ORDER BY a"); |
| 171 | +is( $result, qq(local|11.11|baz|1 |
| 172 | +local|2.2|bar|2), |
| 173 | + 'update works with dropped publisher column'); |
| 174 | + |
| 175 | +$node_subscriber->safe_psql('postgres', |
| 176 | + "ALTER TABLE tab_mixed DROP COLUMN d"); |
| 177 | + |
| 178 | +$node_publisher->safe_psql('postgres', |
| 179 | + "UPDATE tab_mixed SET c = 22.22 WHERE a = 2"); |
| 180 | + |
| 181 | +$node_publisher->poll_query_until('postgres', $caughtup_query) |
| 182 | + or die "Timed out while waiting for subscriber to catch up"; |
| 183 | + |
| 184 | +$result = $node_subscriber->safe_psql('postgres', |
| 185 | + "SELECT * FROM tab_mixed ORDER BY a"); |
| 186 | +is( $result, qq(11.11|baz|1 |
| 187 | +22.22|bar|2), |
| 188 | + 'update works with dropped subscriber column'); |
| 189 | + |
151 | 190 | # check that change of connection string and/or publication list causes
|
152 | 191 | # restart of subscription workers. Not all of these are registered as tests
|
153 | 192 | # as we need to poll for a change but the test suite will fail none the less
|
|
0 commit comments