publication-with-publish-option.td 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. #
  10. # Test that a publication WITH (publish = 'XXX') option is handled
  11. # correctly.
  12. #
  13. > CREATE SECRET pgpass AS 'postgres'
  14. > CREATE CONNECTION pg TO POSTGRES (
  15. HOST postgres,
  16. DATABASE postgres,
  17. USER postgres,
  18. PASSWORD SECRET pgpass
  19. )
  20. $ postgres-execute connection=postgres://postgres:postgres@postgres
  21. ALTER USER postgres WITH replication;
  22. DROP SCHEMA IF EXISTS public CASCADE;
  23. DROP PUBLICATION IF EXISTS mz_source;
  24. CREATE SCHEMA public;
  25. CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
  26. ALTER TABLE t1 REPLICA IDENTITY FULL;
  27. CREATE PUBLICATION mz_source_insert FOR TABLE t1 WITH ( publish = 'insert') ;
  28. CREATE PUBLICATION mz_source_update FOR TABLE t1 WITH ( publish = 'update') ;
  29. CREATE PUBLICATION mz_source_delete FOR TABLE t1 WITH ( publish = 'delete') ;
  30. > CREATE SOURCE mz_source_insert
  31. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source_insert')
  32. FOR TABLES (t1 AS t1_insert);
  33. > CREATE SOURCE mz_source_update
  34. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source_update')
  35. FOR TABLES (t1 AS t1_update);
  36. > CREATE SOURCE mz_source_delete
  37. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source_delete')
  38. FOR TABLES (t1 AS t1_delete);
  39. # Make sure that the above sources are fully instantiated
  40. # (that is, we have finished absorbing their snapshots),
  41. # so that the DML statements below are sent as actual replication
  42. # events post-snapshot.
  43. #
  44. # Currently there is no good way to do this other than sleeping.
  45. # <https://github.com/MaterializeInc/database-issues/issues/4266> tracks
  46. # making this better
  47. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration=10s
  48. > SELECT COUNT(*) FROM mz_source_insert;
  49. 0
  50. > SELECT COUNT(*) FROM mz_source_update;
  51. 0
  52. > SELECT COUNT(*) FROM mz_source_delete;
  53. 0
  54. $ postgres-execute connection=postgres://postgres:postgres@postgres
  55. INSERT INTO t1 VALUES (1);
  56. UPDATE t1 SET f1 = 2 WHERE f1 = 1;
  57. DELETE FROM t1;
  58. > SELECT * FROM t1_insert;
  59. 1
  60. ! SELECT * FROM t1_update;
  61. contains:Invalid data in source, saw retractions (1) for row that does not exist
  62. ! SELECT * FROM t1_delete;
  63. contains:Invalid data in source, saw retractions (1) for row that does not exist