|
3 | 3 | use warnings;
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::More tests => 17; |
| 6 | +use Test::More tests => 20; |
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 | $node_publisher->safe_psql('postgres',
|
35 | 35 | "CREATE TABLE tab_include (a int, b text, CONSTRAINT covering PRIMARY KEY(a) INCLUDE(b))"
|
36 | 36 | );
|
|
45 | 45 |
|
46 | 46 | # different column count and order than on publisher
|
47 | 47 | $node_subscriber->safe_psql('postgres',
|
48 |
| - "CREATE TABLE tab_mixed (c text, b text, a int primary key)"); |
| 48 | + "CREATE TABLE tab_mixed (d text default 'local', c numeric, b text, a int primary key)" |
| 49 | +); |
49 | 50 |
|
50 | 51 | # replication of the table with included index
|
51 | 52 | $node_subscriber->safe_psql('postgres',
|
|
94 | 95 | $node_publisher->safe_psql('postgres', "UPDATE tab_rep SET a = -a");
|
95 | 96 |
|
96 | 97 | $node_publisher->safe_psql('postgres',
|
97 |
| - "INSERT INTO tab_mixed VALUES (2, 'bar')"); |
| 98 | + "INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)"); |
98 | 99 |
|
99 | 100 | $node_publisher->safe_psql('postgres',
|
100 | 101 | "INSERT INTO tab_include SELECT generate_series(1,50)");
|
|
112 | 113 | "SELECT count(*), min(a), max(a) FROM tab_rep");
|
113 | 114 | is($result, qq(20|-20|-1), 'check replicated changes on subscriber');
|
114 | 115 |
|
115 |
| -$result = |
116 |
| - $node_subscriber->safe_psql('postgres', "SELECT c, b, a FROM tab_mixed"); |
117 |
| -is( $result, qq(|foo|1 |
118 |
| -|bar|2), 'check replicated changes with different column order'); |
| 116 | +$result = $node_subscriber->safe_psql('postgres', "SELECT * FROM tab_mixed"); |
| 117 | +is( $result, qq(local|1.1|foo|1 |
| 118 | +local|2.2|bar|2), 'check replicated changes with different column order'); |
119 | 119 |
|
120 | 120 | $result = $node_subscriber->safe_psql('postgres',
|
121 | 121 | "SELECT count(*), min(a), max(a) FROM tab_include");
|
|
139 | 139 | "ALTER TABLE tab_ins REPLICA IDENTITY FULL");
|
140 | 140 | $node_subscriber->safe_psql('postgres',
|
141 | 141 | "ALTER TABLE tab_ins REPLICA IDENTITY FULL");
|
| 142 | +# tab_mixed can use DEFAULT, since it has a primary key |
142 | 143 |
|
143 | 144 | # and do the updates
|
144 | 145 | $node_publisher->safe_psql('postgres', "UPDATE tab_full SET a = a * a");
|
145 | 146 | $node_publisher->safe_psql('postgres',
|
146 | 147 | "UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'");
|
| 148 | +$node_publisher->safe_psql('postgres', |
| 149 | + "UPDATE tab_mixed SET b = 'baz' WHERE a = 1"); |
147 | 150 |
|
148 | 151 | $node_publisher->wait_for_catchup('tap_sub');
|
149 | 152 |
|
|
159 | 162 | bb),
|
160 | 163 | 'update works with REPLICA IDENTITY FULL and text datums');
|
161 | 164 |
|
| 165 | +$result = $node_subscriber->safe_psql('postgres', |
| 166 | + "SELECT * FROM tab_mixed ORDER BY a"); |
| 167 | +is( $result, qq(local|1.1|baz|1 |
| 168 | +local|2.2|bar|2), |
| 169 | + 'update works with different column order and subscriber local values'); |
| 170 | + |
| 171 | +# check behavior with dropped columns |
| 172 | + |
| 173 | +$node_publisher->safe_psql('postgres', "ALTER TABLE tab_mixed DROP COLUMN b"); |
| 174 | +$node_publisher->safe_psql('postgres', |
| 175 | + "UPDATE tab_mixed SET c = 11.11 WHERE a = 1"); |
| 176 | + |
| 177 | +$node_publisher->wait_for_catchup('tap_sub'); |
| 178 | + |
| 179 | +$result = $node_subscriber->safe_psql('postgres', |
| 180 | + "SELECT * FROM tab_mixed ORDER BY a"); |
| 181 | +is( $result, qq(local|11.11|baz|1 |
| 182 | +local|2.2|bar|2), |
| 183 | + 'update works with dropped publisher column'); |
| 184 | + |
| 185 | +$node_subscriber->safe_psql('postgres', |
| 186 | + "ALTER TABLE tab_mixed DROP COLUMN d"); |
| 187 | + |
| 188 | +$node_publisher->safe_psql('postgres', |
| 189 | + "UPDATE tab_mixed SET c = 22.22 WHERE a = 2"); |
| 190 | + |
| 191 | +$node_publisher->wait_for_catchup('tap_sub'); |
| 192 | + |
| 193 | +$result = $node_subscriber->safe_psql('postgres', |
| 194 | + "SELECT * FROM tab_mixed ORDER BY a"); |
| 195 | +is( $result, qq(11.11|baz|1 |
| 196 | +22.22|bar|2), |
| 197 | + 'update works with dropped subscriber column'); |
| 198 | + |
162 | 199 | # check that change of connection string and/or publication list causes
|
163 | 200 | # restart of subscription workers. Not all of these are registered as tests
|
164 | 201 | # as we need to poll for a change but the test suite will fail none the less
|
|
0 commit comments