alter-column-irrelevant.td 1.7 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. $ set-sql-timeout duration=1s
  10. #
  11. # Test ALTER TABLE -- some column changes should not do any harm
  12. #
  13. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  14. > CREATE CONNECTION mysql_conn TO MYSQL (
  15. HOST mysql,
  16. USER root,
  17. PASSWORD SECRET mysqlpass
  18. )
  19. $ mysql-connect name=mysql url=mysql://root@mysql password=${arg.mysql-root-password}
  20. $ mysql-execute name=mysql
  21. DROP DATABASE IF EXISTS public;
  22. CREATE DATABASE public;
  23. USE public;
  24. CREATE TABLE t1 (f1 INTEGER);
  25. INSERT INTO t1 VALUES (1);
  26. CREATE TABLE t2 (f1 INTEGER);
  27. INSERT INTO t2 VALUES (1);
  28. > CREATE SOURCE mz_source
  29. FROM MYSQL CONNECTION mysql_conn
  30. FOR ALL TABLES;
  31. > SELECT * FROM t1;
  32. 1
  33. # just add a new column to t1
  34. $ mysql-execute name=mysql
  35. ALTER TABLE t1 ADD COLUMN f2 INTEGER;
  36. INSERT INTO t1 VALUES (2, 2);
  37. > SELECT * FROM t1;
  38. 1
  39. 2
  40. # add a new column to t1 at the beginning of
  41. $ mysql-execute name=mysql
  42. ALTER TABLE t1 ADD COLUMN f3 INTEGER FIRST;
  43. INSERT INTO t1 VALUES (3, 3, 3);
  44. ! SELECT * FROM t1;
  45. contains:incompatible schema change
  46. # add a new column to t2
  47. $ mysql-execute name=mysql
  48. ALTER TABLE t2 ADD COLUMN f2 INTEGER;
  49. INSERT INTO t2 VALUES (2, 2);
  50. > SELECT * FROM t2;
  51. 1
  52. 2
  53. # drop the column added after source creation
  54. $ mysql-execute name=mysql
  55. ALTER TABLE t2 DROP COLUMN f2;
  56. # t2 still works
  57. > SELECT * FROM t2;
  58. 1
  59. 2