-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathv0019_add_env_suffix_target.py
More file actions
35 lines (28 loc) · 1 KB
/
v0019_add_env_suffix_target.py
File metadata and controls
35 lines (28 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Add support for environment suffix target."""
from sqlglot import exp
def migrate_ddl(state_sync, **kwargs): # type: ignore
engine_adapter = state_sync.engine_adapter
environments_table = "_environments"
if state_sync.schema:
environments_table = f"{state_sync.schema}.{environments_table}"
alter_table_exp = exp.Alter(
this=exp.to_table(environments_table),
kind="TABLE",
actions=[
exp.ColumnDef(
this=exp.to_column("suffix_target"),
kind=exp.DataType.build("text"),
)
],
)
engine_adapter.execute(alter_table_exp)
def migrate_dml(state_sync, **kwargs): # type: ignore
engine_adapter = state_sync.engine_adapter
environments_table = "_environments"
if state_sync.schema:
environments_table = f"{state_sync.schema}.{environments_table}"
state_sync.engine_adapter.update_table(
environments_table,
{"suffix_target": "schema"},
where="1=1",
)