Skip to content

Commit 61b0c99

Browse files
committed
refactor: integrate alembic in the init command
1 parent 1767a10 commit 61b0c99

File tree

6 files changed

+405
-7
lines changed

6 files changed

+405
-7
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2022 TOSIT.IO
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Initial table creation
5+
6+
Revision ID: tdp_lib_1.1
7+
Revises:
8+
Create Date: 2024-06-11 09:59:57.688453
9+
10+
"""
11+
from typing import Sequence, Union
12+
13+
import sqlalchemy as sa
14+
from alembic import op
15+
16+
# revision identifiers, used by Alembic.
17+
revision: str = "tdp_lib_1.1"
18+
down_revision: Union[str, None] = None
19+
branch_labels: Union[str, Sequence[str], None] = None
20+
depends_on: Union[str, Sequence[str], None] = None
21+
22+
23+
def upgrade() -> None:
24+
# ### commands auto generated by Alembic - please adjust! ###
25+
op.create_table(
26+
"deployment",
27+
sa.Column("id", sa.Integer(), nullable=False),
28+
sa.Column("options", sa.JSON(none_as_null=True), nullable=True),
29+
sa.Column("start_time", sa.DateTime(), nullable=True),
30+
sa.Column("end_time", sa.DateTime(), nullable=True),
31+
sa.Column(
32+
"state",
33+
sa.Enum(
34+
"PLANNED", "RUNNING", "SUCCESS", "FAILURE", name="deploymentstateenum"
35+
),
36+
nullable=True,
37+
),
38+
sa.Column(
39+
"deployment_type",
40+
sa.Enum(
41+
"DAG",
42+
"OPERATIONS",
43+
"RESUME",
44+
"RECONFIGURE",
45+
"CUSTOM",
46+
name="deploymenttypeenum",
47+
),
48+
nullable=True,
49+
),
50+
sa.PrimaryKeyConstraint("id"),
51+
)
52+
op.create_table(
53+
"operation",
54+
sa.Column("deployment_id", sa.Integer(), nullable=False),
55+
sa.Column("operation_order", sa.Integer(), nullable=False),
56+
sa.Column("operation", sa.String(length=72), nullable=False),
57+
sa.Column("host", sa.String(length=255), nullable=True),
58+
sa.Column("extra_vars", sa.JSON(none_as_null=True), nullable=True),
59+
sa.Column("start_time", sa.DateTime(), nullable=True),
60+
sa.Column("end_time", sa.DateTime(), nullable=True),
61+
sa.Column(
62+
"state",
63+
sa.Enum(
64+
"PLANNED",
65+
"RUNNING",
66+
"PENDING",
67+
"SUCCESS",
68+
"FAILURE",
69+
"HELD",
70+
name="operationstateenum",
71+
),
72+
nullable=False,
73+
),
74+
sa.Column("logs", sa.LargeBinary(length=10000000), nullable=True),
75+
sa.ForeignKeyConstraint(
76+
["deployment_id"],
77+
["deployment.id"],
78+
),
79+
sa.PrimaryKeyConstraint("deployment_id", "operation_order"),
80+
)
81+
op.create_table(
82+
"sch_status_log",
83+
sa.Column("id", sa.Integer(), nullable=False),
84+
sa.Column("event_time", sa.DateTime(), nullable=False),
85+
sa.Column("service", sa.String(length=20), nullable=False),
86+
sa.Column("component", sa.String(length=30), nullable=True),
87+
sa.Column("host", sa.String(length=255), nullable=True),
88+
sa.Column("running_version", sa.String(length=40), nullable=True),
89+
sa.Column("configured_version", sa.String(length=40), nullable=True),
90+
sa.Column("to_config", sa.Boolean(), nullable=True),
91+
sa.Column("to_restart", sa.Boolean(), nullable=True),
92+
sa.Column("is_active", sa.Boolean(), nullable=True),
93+
sa.Column(
94+
"source",
95+
sa.Enum(
96+
"DEPLOYMENT", "FORCED", "STALE", "MANUAL", name="schstatuslogsourceenum"
97+
),
98+
nullable=False,
99+
),
100+
sa.Column("deployment_id", sa.Integer(), nullable=True),
101+
sa.Column("message", sa.String(length=512), nullable=True),
102+
sa.ForeignKeyConstraint(
103+
["deployment_id"],
104+
["deployment.id"],
105+
),
106+
sa.PrimaryKeyConstraint("id"),
107+
)
108+
# ### end Alembic commands ###
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Copyright 2022 TOSIT.IO
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Initial table creation
5+
6+
Revision ID: tdp_lib_1.1
7+
Revises:
8+
Create Date: 2024-06-11 10:00:08.925442
9+
10+
"""
11+
from typing import Sequence, Union
12+
13+
import sqlalchemy as sa
14+
from alembic import op
15+
from sqlalchemy.dialects import postgresql
16+
17+
# revision identifiers, used by Alembic.
18+
revision: str = "tdp_lib_1.1"
19+
down_revision: Union[str, None] = None
20+
branch_labels: Union[str, Sequence[str], None] = None
21+
depends_on: Union[str, Sequence[str], None] = None
22+
23+
24+
def upgrade() -> None:
25+
# ### commands auto generated by Alembic - please adjust! ###
26+
sa.Enum(
27+
"DEPLOYMENT", "FORCED", "STALE", "MANUAL", name="schstatuslogsourceenum"
28+
).create(op.get_bind())
29+
sa.Enum(
30+
"DAG",
31+
"OPERATIONS",
32+
"RESUME",
33+
"RECONFIGURE",
34+
"CUSTOM",
35+
name="deploymenttypeenum",
36+
).create(op.get_bind())
37+
sa.Enum(
38+
"PLANNED", "RUNNING", "SUCCESS", "FAILURE", name="deploymentstateenum"
39+
).create(op.get_bind())
40+
sa.Enum(
41+
"PLANNED",
42+
"RUNNING",
43+
"PENDING",
44+
"SUCCESS",
45+
"FAILURE",
46+
"HELD",
47+
name="operationstateenum",
48+
).create(op.get_bind())
49+
op.create_table(
50+
"deployment",
51+
sa.Column("id", sa.Integer(), nullable=False),
52+
sa.Column("options", sa.JSON(none_as_null=True), nullable=True),
53+
sa.Column("start_time", sa.DateTime(), nullable=True),
54+
sa.Column("end_time", sa.DateTime(), nullable=True),
55+
sa.Column(
56+
"state",
57+
postgresql.ENUM(
58+
"PLANNED",
59+
"RUNNING",
60+
"SUCCESS",
61+
"FAILURE",
62+
name="deploymentstateenum",
63+
create_type=False,
64+
),
65+
nullable=True,
66+
),
67+
sa.Column(
68+
"deployment_type",
69+
postgresql.ENUM(
70+
"DAG",
71+
"OPERATIONS",
72+
"RESUME",
73+
"RECONFIGURE",
74+
"CUSTOM",
75+
name="deploymenttypeenum",
76+
create_type=False,
77+
),
78+
nullable=True,
79+
),
80+
sa.PrimaryKeyConstraint("id"),
81+
)
82+
op.create_table(
83+
"operation",
84+
sa.Column("deployment_id", sa.Integer(), nullable=False),
85+
sa.Column("operation_order", sa.Integer(), nullable=False),
86+
sa.Column("operation", sa.String(length=72), nullable=False),
87+
sa.Column("host", sa.String(length=255), nullable=True),
88+
sa.Column("extra_vars", sa.JSON(none_as_null=True), nullable=True),
89+
sa.Column("start_time", sa.DateTime(), nullable=True),
90+
sa.Column("end_time", sa.DateTime(), nullable=True),
91+
sa.Column(
92+
"state",
93+
postgresql.ENUM(
94+
"PLANNED",
95+
"RUNNING",
96+
"PENDING",
97+
"SUCCESS",
98+
"FAILURE",
99+
"HELD",
100+
name="operationstateenum",
101+
create_type=False,
102+
),
103+
nullable=False,
104+
),
105+
sa.Column("logs", sa.LargeBinary(length=10000000), nullable=True),
106+
sa.ForeignKeyConstraint(
107+
["deployment_id"],
108+
["deployment.id"],
109+
),
110+
sa.PrimaryKeyConstraint("deployment_id", "operation_order"),
111+
)
112+
op.create_table(
113+
"sch_status_log",
114+
sa.Column("id", sa.Integer(), nullable=False),
115+
sa.Column("event_time", sa.DateTime(), nullable=False),
116+
sa.Column("service", sa.String(length=20), nullable=False),
117+
sa.Column("component", sa.String(length=30), nullable=True),
118+
sa.Column("host", sa.String(length=255), nullable=True),
119+
sa.Column("running_version", sa.String(length=40), nullable=True),
120+
sa.Column("configured_version", sa.String(length=40), nullable=True),
121+
sa.Column("to_config", sa.Boolean(), nullable=True),
122+
sa.Column("to_restart", sa.Boolean(), nullable=True),
123+
sa.Column("is_active", sa.Boolean(), nullable=True),
124+
sa.Column(
125+
"source",
126+
postgresql.ENUM(
127+
"DEPLOYMENT",
128+
"FORCED",
129+
"STALE",
130+
"MANUAL",
131+
name="schstatuslogsourceenum",
132+
create_type=False,
133+
),
134+
nullable=False,
135+
),
136+
sa.Column("deployment_id", sa.Integer(), nullable=True),
137+
sa.Column("message", sa.String(length=512), nullable=True),
138+
sa.ForeignKeyConstraint(
139+
["deployment_id"],
140+
["deployment.id"],
141+
),
142+
sa.PrimaryKeyConstraint("id"),
143+
)
144+
# ### end Alembic commands ###
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2022 TOSIT.IO
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Initial table creation
5+
6+
Revision ID: tdp_lib_1.1
7+
Revises:
8+
Create Date: 2024-06-11 09:59:29.908273
9+
10+
"""
11+
from typing import Sequence, Union
12+
13+
import sqlalchemy as sa
14+
from alembic import op
15+
16+
# revision identifiers, used by Alembic.
17+
revision: str = "tdp_lib_1.1"
18+
down_revision: Union[str, None] = None
19+
branch_labels: Union[str, Sequence[str], None] = None
20+
depends_on: Union[str, Sequence[str], None] = None
21+
22+
23+
def upgrade() -> None:
24+
# ### commands auto generated by Alembic - please adjust! ###
25+
op.create_table(
26+
"deployment",
27+
sa.Column("id", sa.Integer(), nullable=False),
28+
sa.Column("options", sa.JSON(none_as_null=True), nullable=True),
29+
sa.Column("start_time", sa.DateTime(), nullable=True),
30+
sa.Column("end_time", sa.DateTime(), nullable=True),
31+
sa.Column(
32+
"state",
33+
sa.Enum(
34+
"PLANNED", "RUNNING", "SUCCESS", "FAILURE", name="deploymentstateenum"
35+
),
36+
nullable=True,
37+
),
38+
sa.Column(
39+
"deployment_type",
40+
sa.Enum(
41+
"DAG",
42+
"OPERATIONS",
43+
"RESUME",
44+
"RECONFIGURE",
45+
"CUSTOM",
46+
name="deploymenttypeenum",
47+
),
48+
nullable=True,
49+
),
50+
sa.PrimaryKeyConstraint("id"),
51+
)
52+
op.create_table(
53+
"operation",
54+
sa.Column("deployment_id", sa.Integer(), nullable=False),
55+
sa.Column("operation_order", sa.Integer(), nullable=False),
56+
sa.Column("operation", sa.String(length=72), nullable=False),
57+
sa.Column("host", sa.String(length=255), nullable=True),
58+
sa.Column("extra_vars", sa.JSON(none_as_null=True), nullable=True),
59+
sa.Column("start_time", sa.DateTime(), nullable=True),
60+
sa.Column("end_time", sa.DateTime(), nullable=True),
61+
sa.Column(
62+
"state",
63+
sa.Enum(
64+
"PLANNED",
65+
"RUNNING",
66+
"PENDING",
67+
"SUCCESS",
68+
"FAILURE",
69+
"HELD",
70+
name="operationstateenum",
71+
),
72+
nullable=False,
73+
),
74+
sa.Column("logs", sa.LargeBinary(length=10000000), nullable=True),
75+
sa.ForeignKeyConstraint(
76+
["deployment_id"],
77+
["deployment.id"],
78+
),
79+
sa.PrimaryKeyConstraint("deployment_id", "operation_order"),
80+
)
81+
op.create_table(
82+
"sch_status_log",
83+
sa.Column("id", sa.Integer(), nullable=False),
84+
sa.Column("event_time", sa.DateTime(), nullable=False),
85+
sa.Column("service", sa.String(length=20), nullable=False),
86+
sa.Column("component", sa.String(length=30), nullable=True),
87+
sa.Column("host", sa.String(length=255), nullable=True),
88+
sa.Column("running_version", sa.String(length=40), nullable=True),
89+
sa.Column("configured_version", sa.String(length=40), nullable=True),
90+
sa.Column("to_config", sa.Boolean(), nullable=True),
91+
sa.Column("to_restart", sa.Boolean(), nullable=True),
92+
sa.Column("is_active", sa.Boolean(), nullable=True),
93+
sa.Column(
94+
"source",
95+
sa.Enum(
96+
"DEPLOYMENT", "FORCED", "STALE", "MANUAL", name="schstatuslogsourceenum"
97+
),
98+
nullable=False,
99+
),
100+
sa.Column("deployment_id", sa.Integer(), nullable=True),
101+
sa.Column("message", sa.String(length=512), nullable=True),
102+
sa.ForeignKeyConstraint(
103+
["deployment_id"],
104+
["deployment.id"],
105+
),
106+
sa.PrimaryKeyConstraint("id"),
107+
)
108+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)