Module materialize.checks.all_checks.swap_schema
Expand source code Browse git
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
from textwrap import dedent
from materialize.checks.actions import Testdrive
from materialize.checks.checks import Check
from materialize.checks.executors import Executor
from materialize.mz_version import MzVersion
class SwapSchema(Check):
def _can_run(self, e: Executor) -> bool:
return self.base_version >= MzVersion.parse_mz("v0.75.0-dev")
def initialize(self) -> Testdrive:
return Testdrive(
dedent(
"""
> CREATE SCHEMA swap_me1;
> CREATE SCHEMA swap_me2;
> CREATE SCHEMA swap_me3;
> CREATE SCHEMA swap_me4;
> CREATE TABLE swap_me1.t1 (f1 INTEGER);
> CREATE TABLE swap_me2.t2 (f1 INTEGER);
> CREATE TABLE swap_me3.t3 (f1 INTEGER);
> CREATE TABLE swap_me4.t4 (f1 INTEGER);
> INSERT INTO swap_me1.t1 VALUES (1);
> INSERT INTO swap_me2.t2 VALUES (2);
> INSERT INTO swap_me3.t3 VALUES (3);
> INSERT INTO swap_me4.t4 VALUES (4);
"""
)
)
def manipulate(self) -> list[Testdrive]:
return [
Testdrive(dedent(s))
for s in [
"""
> ALTER SCHEMA swap_me1 SWAP WITH swap_me2;
""",
"""
> ALTER SCHEMA swap_me3 SWAP WITH swap_me4;
""",
]
]
def validate(self) -> Testdrive:
return Testdrive(
dedent(
"""
> SHOW SCHEMAS LIKE 'swap_me%';
swap_me1
swap_me2
swap_me3
swap_me4
> SET SCHEMA = swap_me1;
> SELECT * FROM t2;
2
> SET SCHEMA = swap_me2;
> SELECT * FROM t1;
1
> SET SCHEMA = swap_me3;
> SELECT * FROM t4;
4
> SET SCHEMA = swap_me4;
> SELECT * FROM t3;
3
"""
)
)
Classes
class SwapSchema (base_version: MzVersion, rng: random.Random | None)
-
Expand source code Browse git
class SwapSchema(Check): def _can_run(self, e: Executor) -> bool: return self.base_version >= MzVersion.parse_mz("v0.75.0-dev") def initialize(self) -> Testdrive: return Testdrive( dedent( """ > CREATE SCHEMA swap_me1; > CREATE SCHEMA swap_me2; > CREATE SCHEMA swap_me3; > CREATE SCHEMA swap_me4; > CREATE TABLE swap_me1.t1 (f1 INTEGER); > CREATE TABLE swap_me2.t2 (f1 INTEGER); > CREATE TABLE swap_me3.t3 (f1 INTEGER); > CREATE TABLE swap_me4.t4 (f1 INTEGER); > INSERT INTO swap_me1.t1 VALUES (1); > INSERT INTO swap_me2.t2 VALUES (2); > INSERT INTO swap_me3.t3 VALUES (3); > INSERT INTO swap_me4.t4 VALUES (4); """ ) ) def manipulate(self) -> list[Testdrive]: return [ Testdrive(dedent(s)) for s in [ """ > ALTER SCHEMA swap_me1 SWAP WITH swap_me2; """, """ > ALTER SCHEMA swap_me3 SWAP WITH swap_me4; """, ] ] def validate(self) -> Testdrive: return Testdrive( dedent( """ > SHOW SCHEMAS LIKE 'swap_me%'; swap_me1 swap_me2 swap_me3 swap_me4 > SET SCHEMA = swap_me1; > SELECT * FROM t2; 2 > SET SCHEMA = swap_me2; > SELECT * FROM t1; 1 > SET SCHEMA = swap_me3; > SELECT * FROM t4; 4 > SET SCHEMA = swap_me4; > SELECT * FROM t3; 3 """ ) )
Ancestors
Methods
def initialize(self) ‑> Testdrive
-
Expand source code Browse git
def initialize(self) -> Testdrive: return Testdrive( dedent( """ > CREATE SCHEMA swap_me1; > CREATE SCHEMA swap_me2; > CREATE SCHEMA swap_me3; > CREATE SCHEMA swap_me4; > CREATE TABLE swap_me1.t1 (f1 INTEGER); > CREATE TABLE swap_me2.t2 (f1 INTEGER); > CREATE TABLE swap_me3.t3 (f1 INTEGER); > CREATE TABLE swap_me4.t4 (f1 INTEGER); > INSERT INTO swap_me1.t1 VALUES (1); > INSERT INTO swap_me2.t2 VALUES (2); > INSERT INTO swap_me3.t3 VALUES (3); > INSERT INTO swap_me4.t4 VALUES (4); """ ) )
def manipulate(self) ‑> list[Testdrive]
-
Expand source code Browse git
def manipulate(self) -> list[Testdrive]: return [ Testdrive(dedent(s)) for s in [ """ > ALTER SCHEMA swap_me1 SWAP WITH swap_me2; """, """ > ALTER SCHEMA swap_me3 SWAP WITH swap_me4; """, ] ]
def validate(self) ‑> Testdrive
-
Expand source code Browse git
def validate(self) -> Testdrive: return Testdrive( dedent( """ > SHOW SCHEMAS LIKE 'swap_me%'; swap_me1 swap_me2 swap_me3 swap_me4 > SET SCHEMA = swap_me1; > SELECT * FROM t2; 2 > SET SCHEMA = swap_me2; > SELECT * FROM t1; 1 > SET SCHEMA = swap_me3; > SELECT * FROM t4; 4 > SET SCHEMA = swap_me4; > SELECT * FROM t3; 3 """ ) )