05-add-column-primary-key.td 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 adding a primary key as a completely new column does not mess things up
  11. # Currently rejected by the schema registry on the Debezium side. Replication stops
  12. #
  13. # TODO: Reenable when database-issues#2047 is fixed
  14. $ skip-if
  15. SELECT true
  16. $ postgres-execute connection=postgres://postgres:postgres@postgres
  17. CREATE TABLE alter_add_column_primary_key (f1 INTEGER);
  18. INSERT INTO alter_add_column_primary_key VALUES (123);
  19. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  20. URL '${testdrive.schema-registry-url}'
  21. );
  22. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  23. > CREATE SOURCE alter_add_column_primary_key
  24. FROM KAFKA CONNECTION kafka_conn (TOPIC 'postgres.public.alter_add_column_primary_key');
  25. > CREATE TABLE alter_add_column_primary_key_tbl FROM SOURCE alter_add_column_primary_key (REFERENCE "postgres.public.alter_add_column_primary_key")
  26. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  27. ENVELOPE DEBEZIUM;
  28. > SELECT * FROM alter_add_column_primary_key_tbl;
  29. 123
  30. $ postgres-execute connection=postgres://postgres:postgres@postgres
  31. CREATE SEQUENCE pk_sequence;
  32. ALTER TABLE alter_add_column_primary_key ADD COLUMN pk_column INTEGER PRIMARY KEY DEFAULT nextval('pk_sequence');
  33. INSERT INTO alter_add_column_primary_key VALUES (123,2);
  34. UPDATE alter_add_column_primary_key SET f1 = f1 * 10 WHERE pk_column = 1;
  35. UPDATE alter_add_column_primary_key SET f1 = f1 * 100 WHERE pk_column = 2;
  36. > SELECT * FROM alter_add_column_primary_key_tbl;
  37. 123