Skip to content

Commit df84db9

Browse files
committed
Add migration script for renaming funcapi tables
1 parent f1e9a63 commit df84db9

File tree

1 file changed

+263
-0
lines changed

1 file changed

+263
-0
lines changed
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
"""Rename funcapi tables
2+
3+
Revision ID: f31eefd27b2d
4+
Revises: 1b5c88debc3e
5+
Create Date: 2025-05-09 11:29:37.040127+00:00
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
from sqlalchemy.dialects import postgresql
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "f31eefd27b2d"
15+
down_revision = "1b5c88debc3e"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.create_table(
23+
"funcapi_function_job_collections",
24+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
25+
sa.Column("title", sa.String(), nullable=True),
26+
sa.Column("description", sa.String(), nullable=True),
27+
sa.PrimaryKeyConstraint("uuid", name="funcapi_function_job_collections_pk"),
28+
)
29+
op.create_index(
30+
op.f("ix_funcapi_function_job_collections_uuid"),
31+
"funcapi_function_job_collections",
32+
["uuid"],
33+
unique=False,
34+
)
35+
op.create_table(
36+
"funcapi_functions",
37+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
38+
sa.Column("title", sa.String(), nullable=True),
39+
sa.Column("function_class", sa.String(), nullable=True),
40+
sa.Column("description", sa.String(), nullable=True),
41+
sa.Column("input_schema", sa.JSON(), nullable=True),
42+
sa.Column("output_schema", sa.JSON(), nullable=True),
43+
sa.Column("system_tags", sa.JSON(), nullable=True),
44+
sa.Column("user_tags", sa.JSON(), nullable=True),
45+
sa.Column("class_specific_data", sa.JSON(), nullable=True),
46+
sa.Column("default_inputs", sa.JSON(), nullable=True),
47+
sa.PrimaryKeyConstraint("uuid", name="funcapi_functions_pk"),
48+
)
49+
op.create_index(
50+
op.f("ix_funcapi_functions_uuid"), "funcapi_functions", ["uuid"], unique=False
51+
)
52+
op.create_table(
53+
"funcapi_function_jobs",
54+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
55+
sa.Column("title", sa.String(), nullable=True),
56+
sa.Column("function_uuid", postgresql.UUID(as_uuid=True), nullable=False),
57+
sa.Column("function_class", sa.String(), nullable=True),
58+
sa.Column("status", sa.String(), nullable=True),
59+
sa.Column("inputs", sa.JSON(), nullable=True),
60+
sa.Column("outputs", sa.JSON(), nullable=True),
61+
sa.Column("class_specific_data", sa.JSON(), nullable=True),
62+
sa.ForeignKeyConstraint(
63+
["function_uuid"],
64+
["funcapi_functions.uuid"],
65+
name="fk_function_jobs_to_function_uuid",
66+
onupdate="CASCADE",
67+
ondelete="CASCADE",
68+
),
69+
sa.PrimaryKeyConstraint("uuid", name="funcapi_function_jobs_pk"),
70+
)
71+
op.create_index(
72+
op.f("ix_funcapi_function_jobs_function_uuid"),
73+
"funcapi_function_jobs",
74+
["function_uuid"],
75+
unique=False,
76+
)
77+
op.create_index(
78+
op.f("ix_funcapi_function_jobs_uuid"),
79+
"funcapi_function_jobs",
80+
["uuid"],
81+
unique=False,
82+
)
83+
op.create_table(
84+
"funcapi_function_job_collections_to_function_jobs",
85+
sa.Column(
86+
"function_job_collection_uuid", postgresql.UUID(as_uuid=True), nullable=True
87+
),
88+
sa.Column("function_job_uuid", postgresql.UUID(as_uuid=True), nullable=True),
89+
sa.ForeignKeyConstraint(
90+
["function_job_collection_uuid"],
91+
["funcapi_function_job_collections.uuid"],
92+
name="fk_func_job_coll_to_func_jobs_to_func_job_coll_uuid",
93+
onupdate="CASCADE",
94+
ondelete="CASCADE",
95+
),
96+
sa.ForeignKeyConstraint(
97+
["function_job_uuid"],
98+
["funcapi_function_jobs.uuid"],
99+
name="fk_func_job_coll_to_func_jobs_to_func_job_uuid",
100+
onupdate="CASCADE",
101+
ondelete="CASCADE",
102+
),
103+
)
104+
op.drop_table("function_job_collections_to_function_jobs")
105+
op.drop_index(
106+
"ix_function_job_collections_uuid", table_name="function_job_collections"
107+
)
108+
op.drop_table("function_job_collections")
109+
op.drop_index("ix_function_jobs_function_uuid", table_name="function_jobs")
110+
op.drop_index("ix_function_jobs_uuid", table_name="function_jobs")
111+
op.drop_table("function_jobs")
112+
op.drop_index("ix_functions_uuid", table_name="functions")
113+
op.drop_table("functions")
114+
# ### end Alembic commands ###
115+
116+
117+
def downgrade():
118+
# ### commands auto generated by Alembic - please adjust! ###
119+
op.create_table(
120+
"function_job_collections_to_function_jobs",
121+
sa.Column(
122+
"function_job_collection_uuid",
123+
postgresql.UUID(),
124+
autoincrement=False,
125+
nullable=True,
126+
),
127+
sa.Column(
128+
"function_job_uuid", postgresql.UUID(), autoincrement=False, nullable=True
129+
),
130+
sa.ForeignKeyConstraint(
131+
["function_job_collection_uuid"],
132+
["function_job_collections.uuid"],
133+
name="fk_func_job_coll_to_func_jobs_to_func_job_coll_uuid",
134+
onupdate="CASCADE",
135+
ondelete="CASCADE",
136+
),
137+
sa.ForeignKeyConstraint(
138+
["function_job_uuid"],
139+
["function_jobs.uuid"],
140+
name="fk_func_job_coll_to_func_jobs_to_func_job_uuid",
141+
onupdate="CASCADE",
142+
ondelete="CASCADE",
143+
),
144+
)
145+
op.create_table(
146+
"function_job_collections",
147+
sa.Column("uuid", postgresql.UUID(), autoincrement=False, nullable=False),
148+
sa.Column("title", sa.VARCHAR(), autoincrement=False, nullable=True),
149+
sa.Column("description", sa.VARCHAR(), autoincrement=False, nullable=True),
150+
sa.PrimaryKeyConstraint("uuid", name="function_job_collections_pk"),
151+
)
152+
op.create_index(
153+
"ix_function_job_collections_uuid",
154+
"function_job_collections",
155+
["uuid"],
156+
unique=False,
157+
)
158+
op.create_table(
159+
"functions",
160+
sa.Column("uuid", postgresql.UUID(), autoincrement=False, nullable=False),
161+
sa.Column("title", sa.VARCHAR(), autoincrement=False, nullable=True),
162+
sa.Column("function_class", sa.VARCHAR(), autoincrement=False, nullable=True),
163+
sa.Column("description", sa.VARCHAR(), autoincrement=False, nullable=True),
164+
sa.Column(
165+
"input_schema",
166+
postgresql.JSON(astext_type=sa.Text()),
167+
autoincrement=False,
168+
nullable=True,
169+
),
170+
sa.Column(
171+
"output_schema",
172+
postgresql.JSON(astext_type=sa.Text()),
173+
autoincrement=False,
174+
nullable=True,
175+
),
176+
sa.Column(
177+
"system_tags",
178+
postgresql.JSON(astext_type=sa.Text()),
179+
autoincrement=False,
180+
nullable=True,
181+
),
182+
sa.Column(
183+
"user_tags",
184+
postgresql.JSON(astext_type=sa.Text()),
185+
autoincrement=False,
186+
nullable=True,
187+
),
188+
sa.Column(
189+
"class_specific_data",
190+
postgresql.JSON(astext_type=sa.Text()),
191+
autoincrement=False,
192+
nullable=True,
193+
),
194+
sa.Column(
195+
"default_inputs",
196+
postgresql.JSON(astext_type=sa.Text()),
197+
autoincrement=False,
198+
nullable=True,
199+
),
200+
sa.PrimaryKeyConstraint("uuid", name="functions_pk"),
201+
postgresql_ignore_search_path=False,
202+
)
203+
op.create_index("ix_functions_uuid", "functions", ["uuid"], unique=False)
204+
op.create_table(
205+
"function_jobs",
206+
sa.Column("uuid", postgresql.UUID(), autoincrement=False, nullable=False),
207+
sa.Column("title", sa.VARCHAR(), autoincrement=False, nullable=True),
208+
sa.Column(
209+
"function_uuid", postgresql.UUID(), autoincrement=False, nullable=False
210+
),
211+
sa.Column("function_class", sa.VARCHAR(), autoincrement=False, nullable=True),
212+
sa.Column("status", sa.VARCHAR(), autoincrement=False, nullable=True),
213+
sa.Column(
214+
"inputs",
215+
postgresql.JSON(astext_type=sa.Text()),
216+
autoincrement=False,
217+
nullable=True,
218+
),
219+
sa.Column(
220+
"outputs",
221+
postgresql.JSON(astext_type=sa.Text()),
222+
autoincrement=False,
223+
nullable=True,
224+
),
225+
sa.Column(
226+
"class_specific_data",
227+
postgresql.JSON(astext_type=sa.Text()),
228+
autoincrement=False,
229+
nullable=True,
230+
),
231+
sa.ForeignKeyConstraint(
232+
["function_uuid"],
233+
["functions.uuid"],
234+
name="fk_functions_to_function_jobs_to_function_uuid",
235+
onupdate="CASCADE",
236+
ondelete="CASCADE",
237+
),
238+
sa.PrimaryKeyConstraint("uuid", name="function_jobs_pk"),
239+
)
240+
op.create_index("ix_function_jobs_uuid", "function_jobs", ["uuid"], unique=False)
241+
op.create_index(
242+
"ix_function_jobs_function_uuid",
243+
"function_jobs",
244+
["function_uuid"],
245+
unique=False,
246+
)
247+
op.drop_table("funcapi_function_job_collections_to_function_jobs")
248+
op.drop_index(
249+
op.f("ix_funcapi_function_job_collections_uuid"),
250+
table_name="funcapi_function_job_collections",
251+
)
252+
op.drop_table("funcapi_function_job_collections")
253+
op.drop_index(
254+
op.f("ix_funcapi_function_jobs_uuid"), table_name="funcapi_function_jobs"
255+
)
256+
op.drop_index(
257+
op.f("ix_funcapi_function_jobs_function_uuid"),
258+
table_name="funcapi_function_jobs",
259+
)
260+
op.drop_table("funcapi_function_jobs")
261+
op.drop_index(op.f("ix_funcapi_functions_uuid"), table_name="funcapi_functions")
262+
op.drop_table("funcapi_functions")
263+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)