rename_table.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. from textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check
  12. class RenameTable(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE rename_table1 (f1 INTEGER);
  18. > INSERT INTO rename_table1 VALUES (1);
  19. > CREATE MATERIALIZED VIEW rename_table_view AS SELECT DISTINCT f1 FROM rename_table1;
  20. """
  21. )
  22. )
  23. def manipulate(self) -> list[Testdrive]:
  24. return [
  25. Testdrive(dedent(s))
  26. for s in [
  27. """
  28. > INSERT INTO rename_table1 VALUES (2);
  29. > ALTER TABLE rename_table1 RENAME TO rename_table2;
  30. > INSERT INTO rename_table2 VALUES (3);
  31. """,
  32. """
  33. > INSERT INTO rename_table2 VALUES (4);
  34. > ALTER TABLE rename_table2 RENAME TO rename_table3;
  35. > INSERT INTO rename_table3 VALUES (5);
  36. """,
  37. ]
  38. ]
  39. def validate(self) -> Testdrive:
  40. return Testdrive(
  41. dedent(
  42. """
  43. > SELECT * FROM rename_table3;
  44. 1
  45. 2
  46. 3
  47. 4
  48. 5
  49. > SELECT * FROM rename_table_view;
  50. 1
  51. 2
  52. 3
  53. 4
  54. 5
  55. """
  56. )
  57. )