Edit on GitHub

Use LONGTEXT type for blob fields in MySQL.

 1"""Use LONGTEXT type for blob fields in MySQL."""
 2
 3from sqlglot import exp
 4
 5
 6def migrate(state_sync, **kwargs):  # type: ignore
 7    engine_adapter = state_sync.engine_adapter
 8    if engine_adapter.dialect != "mysql":
 9        return
10
11    schema = state_sync.schema
12    environments_table = "_environments"
13    snapshots_table = "_snapshots"
14    seeds_table = "_seeds"
15    plan_dags_table = "_plan_dags"
16
17    if schema:
18        environments_table = f"{schema}.{environments_table}"
19        snapshots_table = f"{schema}.{snapshots_table}"
20        seeds_table = f"{state_sync.schema}.{seeds_table}"
21        plan_dags_table = f"{schema}.{plan_dags_table}"
22
23    targets = [
24        (environments_table, "snapshots"),
25        (snapshots_table, "snapshot"),
26        (seeds_table, "content"),
27        (plan_dags_table, "dag_spec"),
28    ]
29
30    for table_name, column_name in targets:
31        alter_table_exp = exp.AlterTable(
32            this=exp.to_table(table_name),
33            actions=[
34                exp.AlterColumn(
35                    this=exp.to_column(column_name),
36                    dtype=exp.DataType.build("longtext"),
37                )
38            ],
39        )
40
41        engine_adapter.execute(alter_table_exp)
def migrate(state_sync, **kwargs):
 7def migrate(state_sync, **kwargs):  # type: ignore
 8    engine_adapter = state_sync.engine_adapter
 9    if engine_adapter.dialect != "mysql":
10        return
11
12    schema = state_sync.schema
13    environments_table = "_environments"
14    snapshots_table = "_snapshots"
15    seeds_table = "_seeds"
16    plan_dags_table = "_plan_dags"
17
18    if schema:
19        environments_table = f"{schema}.{environments_table}"
20        snapshots_table = f"{schema}.{snapshots_table}"
21        seeds_table = f"{state_sync.schema}.{seeds_table}"
22        plan_dags_table = f"{schema}.{plan_dags_table}"
23
24    targets = [
25        (environments_table, "snapshots"),
26        (snapshots_table, "snapshot"),
27        (seeds_table, "content"),
28        (plan_dags_table, "dag_spec"),
29    ]
30
31    for table_name, column_name in targets:
32        alter_table_exp = exp.AlterTable(
33            this=exp.to_table(table_name),
34            actions=[
35                exp.AlterColumn(
36                    this=exp.to_column(column_name),
37                    dtype=exp.DataType.build("longtext"),
38                )
39            ],
40        )
41
42        engine_adapter.execute(alter_table_exp)