|
70 | 70 | pass('index predicates do not cause crash');
|
71 | 71 |
|
72 | 72 | # We'll re-use these nodes below, so drop their replication state.
|
73 |
| -# We don't bother to drop the tables though. |
74 | 73 | $node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION sub1");
|
75 | 74 | $node_publisher->safe_psql('postgres', "DROP PUBLICATION pub1");
|
| 75 | +# Drop the tables too. |
| 76 | +$node_publisher->safe_psql('postgres', "DROP TABLE tab1"); |
76 | 77 |
|
77 | 78 | $node_publisher->stop('fast');
|
78 | 79 | $node_subscriber->stop('fast');
|
|
307 | 308 | qq(-1|1),
|
308 | 309 | "update works with REPLICA IDENTITY");
|
309 | 310 |
|
| 311 | +# Clean up |
| 312 | +$node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION tap_sub"); |
| 313 | +$node_publisher->safe_psql('postgres', "DROP PUBLICATION tap_pub"); |
| 314 | +$node_publisher->safe_psql('postgres', "DROP TABLE tab_replidentity_index"); |
| 315 | +$node_subscriber->safe_psql('postgres', "DROP TABLE tab_replidentity_index"); |
| 316 | + |
| 317 | +# Test schema invalidation by renaming the schema |
| 318 | + |
| 319 | +# Create tables on publisher |
| 320 | +$node_publisher->safe_psql('postgres', "CREATE SCHEMA sch1"); |
| 321 | +$node_publisher->safe_psql('postgres', "CREATE TABLE sch1.t1 (c1 int)"); |
| 322 | + |
| 323 | +# Create tables on subscriber |
| 324 | +$node_subscriber->safe_psql('postgres', "CREATE SCHEMA sch1"); |
| 325 | +$node_subscriber->safe_psql('postgres', "CREATE TABLE sch1.t1 (c1 int)"); |
| 326 | +$node_subscriber->safe_psql('postgres', "CREATE SCHEMA sch2"); |
| 327 | +$node_subscriber->safe_psql('postgres', "CREATE TABLE sch2.t1 (c1 int)"); |
| 328 | + |
| 329 | +# Setup logical replication that will cover t1 under both schema names |
| 330 | +$node_publisher->safe_psql('postgres', |
| 331 | + "CREATE PUBLICATION tap_pub_sch FOR ALL TABLES"); |
| 332 | +$node_subscriber->safe_psql('postgres', |
| 333 | + "CREATE SUBSCRIPTION tap_sub_sch CONNECTION '$publisher_connstr' PUBLICATION tap_pub_sch" |
| 334 | +); |
| 335 | + |
| 336 | +# Wait for initial table sync to finish |
| 337 | +$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub_sch'); |
| 338 | + |
| 339 | +# Check what happens to data inserted before and after schema rename |
| 340 | +$node_publisher->safe_psql( |
| 341 | + 'postgres', |
| 342 | + "begin; |
| 343 | +insert into sch1.t1 values(1); |
| 344 | +alter schema sch1 rename to sch2; |
| 345 | +create schema sch1; |
| 346 | +create table sch1.t1(c1 int); |
| 347 | +insert into sch1.t1 values(2); |
| 348 | +insert into sch2.t1 values(3); |
| 349 | +commit;"); |
| 350 | + |
| 351 | +$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub_sch'); |
| 352 | + |
| 353 | +# Subscriber's sch1.t1 should receive the row inserted into the new sch1.t1, |
| 354 | +# but not the row inserted into the old sch1.t1 post-rename. |
| 355 | +my $result = $node_subscriber->safe_psql('postgres', "SELECT * FROM sch1.t1"); |
| 356 | +is( $result, qq(1 |
| 357 | +2), 'check data in subscriber sch1.t1 after schema rename'); |
| 358 | + |
| 359 | +# Subscriber's sch2.t1 won't have gotten anything yet ... |
| 360 | +$result = $node_subscriber->safe_psql('postgres', "SELECT * FROM sch2.t1"); |
| 361 | +is($result, '', 'no data yet in subscriber sch2.t1 after schema rename'); |
| 362 | + |
| 363 | +# ... but it should show up after REFRESH. |
| 364 | +$node_subscriber->safe_psql('postgres', |
| 365 | + 'ALTER SUBSCRIPTION tap_sub_sch REFRESH PUBLICATION'); |
| 366 | + |
| 367 | +$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub_sch'); |
| 368 | + |
| 369 | +$result = $node_subscriber->safe_psql('postgres', "SELECT * FROM sch2.t1"); |
| 370 | +is( $result, qq(1 |
| 371 | +3), 'check data in subscriber sch2.t1 after schema rename'); |
| 372 | + |
310 | 373 | $node_publisher->stop('fast');
|
311 | 374 | $node_subscriber->stop('fast');
|
312 | 375 |
|
|
0 commit comments