-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ability to execute custom code while initializing config; A…
…dd tests for custom code; Add remove_blueprint() function; Adjust regexp for placeholders to allow skipping extra space before and after curly braces; Make certain attributes of TableColumn, ViewColumn optional
- Loading branch information
Showing
16 changed files
with
203 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from snowddl import DataType, Ident, TableBlueprint, TableColumn, SchemaObjectIdent, SnowDDLConfig | ||
|
||
|
||
def handler(config: SnowDDLConfig): | ||
# Add custom tables | ||
for i in range(1,5): | ||
bp = TableBlueprint( | ||
full_name=SchemaObjectIdent(config.env_prefix, "test_db", "test_schema", f"custom_table_{i}"), | ||
columns=[ | ||
TableColumn( | ||
name=Ident("id"), | ||
type=DataType("NUMBER(38,0)"), | ||
), | ||
TableColumn( | ||
name=Ident("name"), | ||
type=DataType("VARCHAR(255)"), | ||
), | ||
], | ||
is_transient=True, | ||
comment=f"This table was created programmatically", | ||
) | ||
|
||
config.add_blueprint(bp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from snowddl import SchemaObjectIdent, SnowDDLConfig, TableBlueprint, ViewBlueprint | ||
|
||
|
||
def handler(config: SnowDDLConfig): | ||
# Add view combining all custom tables | ||
parts = [] | ||
|
||
for full_name, bp in config.get_blueprints_by_type_and_pattern(TableBlueprint, "test_db.test_schema.custom_table_*"): | ||
parts.append(f"SELECT id, name FROM {full_name}") | ||
|
||
bp = ViewBlueprint( | ||
full_name=SchemaObjectIdent(config.env_prefix, "test_db", "test_schema", "custom_view"), | ||
text="\nUNION ALL\n".join(parts), | ||
comment=f"This view was created programmatically", | ||
) | ||
|
||
config.add_blueprint(bp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from snowddl import DataType, Ident, SchemaObjectIdent, SnowDDLConfig, TableBlueprint, TableColumn | ||
|
||
def handler(config: SnowDDLConfig): | ||
# Add some custom tables | ||
for i in range(1,5): | ||
bp = TableBlueprint( | ||
full_name=SchemaObjectIdent(config.env_prefix, "db1", "sc1", f"cu001_tb{i}"), | ||
columns=[ | ||
TableColumn( | ||
name=Ident("id"), | ||
type=DataType("NUMBER(38,0)"), | ||
), | ||
TableColumn( | ||
name=Ident("name"), | ||
type=DataType("VARCHAR(255)"), | ||
), | ||
], | ||
is_transient=True, | ||
comment=f"This table was created programmatically", | ||
) | ||
|
||
config.add_blueprint(bp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from snowddl import SnowDDLConfig | ||
|
||
|
||
def handler(config: SnowDDLConfig): | ||
# Empty handler, nothing happens here | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
columns: | ||
id: NUMBER(38,0) | ||
name: VARCHAR(255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
columns: | ||
id: NUMBER(38,0) | ||
name: VARCHAR(255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from snowddl import DataType, Ident, SchemaObjectIdent, SnowDDLConfig, TableBlueprint, TableColumn, ViewBlueprint | ||
|
||
|
||
def handler(config: SnowDDLConfig): | ||
# Add some custom tables and corresponding views | ||
for i in range(1,4): | ||
bp = TableBlueprint( | ||
full_name=SchemaObjectIdent(config.env_prefix, "db1", "sc1", f"cu001_tb{i}"), | ||
columns=[ | ||
TableColumn( | ||
name=Ident("id"), | ||
type=DataType("NUMBER(38,0)"), | ||
), | ||
TableColumn( | ||
name=Ident("name"), | ||
type=DataType("VARCHAR(255)"), | ||
), | ||
], | ||
is_transient=True, | ||
comment=f"This table was created programmatically", | ||
) | ||
|
||
config.add_blueprint(bp) | ||
|
||
bp = ViewBlueprint( | ||
full_name=SchemaObjectIdent(config.env_prefix, "db1", "sc1", f"cu001_vw{i}"), | ||
text=f"SELECT id, name FROM cu001_tb{i}", | ||
comment=f"This view was created programmatically", | ||
) | ||
|
||
config.add_blueprint(bp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from snowddl import SnowDDLConfig, TableBlueprint | ||
|
||
|
||
def handler(config: SnowDDLConfig): | ||
for full_name, bp in config.get_blueprints_by_type_and_pattern(TableBlueprint, "db1.sc1.cu002*").items(): | ||
config.remove_blueprint(bp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
columns: | ||
id: NUMBER(38,0) | ||
name: VARCHAR(255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
columns: | ||
id: NUMBER(38,0) | ||
name: VARCHAR(255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def test_step1(helper): | ||
for i in range(1,5): | ||
table = helper.show_table("db1", "sc1", f"cu001_tb{i}") | ||
assert table is not None | ||
|
||
|
||
def test_step2(helper): | ||
for i in range(1,5): | ||
table = helper.show_table("db1", "sc1", f"cu001_tb{i}") | ||
view = helper.show_view("db1", "sc1", f"cu001_vw{i}") | ||
|
||
if i <= 3: | ||
assert table is not None | ||
assert view is not None | ||
else: | ||
assert table is None | ||
assert view is None | ||
|
||
|
||
def test_step3(helper): | ||
for i in range(1,5): | ||
table = helper.show_table("db1", "sc1", f"cu001_tb{i}") | ||
view = helper.show_view("db1", "sc1", f"cu001_vw{i}") | ||
|
||
assert table is None | ||
assert view is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
def test_step1(helper): | ||
table1 = helper.show_table("db1", "sc1", f"cu002_tb1") | ||
table2 = helper.show_table("db1", "sc1", f"cu002_tb2") | ||
table3 = helper.show_table("db1", "sc1", f"cu002_tb3") | ||
|
||
assert table1 is not None | ||
assert table2 is not None | ||
assert table3 is None | ||
|
||
|
||
def test_step2(helper): | ||
table1 = helper.show_table("db1", "sc1", f"cu002_tb1") | ||
table2 = helper.show_table("db1", "sc1", f"cu002_tb2") | ||
table3 = helper.show_table("db1", "sc1", f"cu002_tb3") | ||
|
||
assert table1 is not None | ||
assert table2 is None | ||
assert table3 is not None | ||
|
||
|
||
def test_step3(helper): | ||
table1 = helper.show_table("db1", "sc1", f"cu002_tb1") | ||
table2 = helper.show_table("db1", "sc1", f"cu002_tb2") | ||
table3 = helper.show_table("db1", "sc1", f"cu002_tb3") | ||
|
||
assert table1 is None | ||
assert table2 is None | ||
assert table3 is None |