support-multiple-materializations.td 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 any replication slot can only be materialized once
  11. #
  12. > CREATE SECRET pgpass AS 'postgres'
  13. > CREATE CONNECTION pg TO POSTGRES (
  14. HOST postgres,
  15. DATABASE postgres,
  16. USER postgres,
  17. PASSWORD SECRET pgpass
  18. )
  19. # Insert data pre-snapshot
  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 (id SERIAL PRIMARY KEY, f1 BOOLEAN);
  26. ALTER TABLE t1 REPLICA IDENTITY FULL;
  27. CREATE TABLE t2 (id SERIAL PRIMARY KEY, t1_id INT REFERENCES t1(id), name VARCHAR);
  28. ALTER TABLE t2 REPLICA IDENTITY FULL;
  29. INSERT INTO t1(f1) VALUES ('true'),('false');
  30. INSERT INTO t2(t1_id, name) VALUES (1, 'example');
  31. CREATE PUBLICATION mz_source FOR ALL TABLES;
  32. > CREATE SOURCE mz_source FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  33. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);
  34. > CREATE TABLE t2 FROM SOURCE mz_source (REFERENCE t2);
  35. > CREATE MATERIALIZED VIEW t1_mat AS
  36. SELECT * FROM t1
  37. > SELECT id, f1 FROM t1_mat;
  38. 1 true
  39. 2 false
  40. > CREATE MATERIALIZED VIEW t1_mat_dupe AS
  41. SELECT * FROM t1
  42. > DROP MATERIALIZED VIEW t1_mat;
  43. > DROP SOURCE mz_source CASCADE;
  44. # verify that dropping things allows recreation
  45. > CREATE SOURCE mz_source FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  46. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);
  47. > CREATE TABLE t2 FROM SOURCE mz_source (REFERENCE t2);
  48. > CREATE MATERIALIZED VIEW joiner AS
  49. SELECT t2.id, t1.f1, t2.name
  50. FROM t1
  51. JOIN t2
  52. ON t1.id = t2.t1_id
  53. > SELECT * FROM joiner;
  54. 1 true example