Skip to content

Commit 834395f

Browse files
committed
Add function db migration script
1 parent 7e4d917 commit 834395f

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
"""Add function tables
2+
3+
Revision ID: e9fe2737bd4d
4+
Revises: 0d52976dc616
5+
Create Date: 2025-05-15 07:32:24.859835+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 = "e9fe2737bd4d"
15+
down_revision = "0d52976dc616"
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.Column(
28+
"created",
29+
sa.DateTime(timezone=True),
30+
server_default=sa.text("now()"),
31+
nullable=False,
32+
),
33+
sa.Column(
34+
"modified",
35+
sa.DateTime(timezone=True),
36+
server_default=sa.text("now()"),
37+
nullable=False,
38+
),
39+
sa.PrimaryKeyConstraint("uuid", name="funcapi_function_job_collections_pk"),
40+
)
41+
op.create_index(
42+
op.f("ix_funcapi_function_job_collections_uuid"),
43+
"funcapi_function_job_collections",
44+
["uuid"],
45+
unique=False,
46+
)
47+
op.create_table(
48+
"funcapi_functions",
49+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
50+
sa.Column("title", sa.String(), nullable=True),
51+
sa.Column("function_class", sa.String(), nullable=True),
52+
sa.Column("description", sa.String(), nullable=True),
53+
sa.Column("input_schema", sa.JSON(), nullable=True),
54+
sa.Column("output_schema", sa.JSON(), nullable=True),
55+
sa.Column("system_tags", sa.JSON(), nullable=True),
56+
sa.Column("user_tags", sa.JSON(), nullable=True),
57+
sa.Column("class_specific_data", sa.JSON(), nullable=True),
58+
sa.Column("default_inputs", sa.JSON(), nullable=True),
59+
sa.Column(
60+
"created",
61+
sa.DateTime(timezone=True),
62+
server_default=sa.text("now()"),
63+
nullable=False,
64+
),
65+
sa.Column(
66+
"modified",
67+
sa.DateTime(timezone=True),
68+
server_default=sa.text("now()"),
69+
nullable=False,
70+
),
71+
sa.PrimaryKeyConstraint("uuid", name="funcapi_functions_pk"),
72+
)
73+
op.create_index(
74+
op.f("ix_funcapi_functions_uuid"), "funcapi_functions", ["uuid"], unique=False
75+
)
76+
op.create_table(
77+
"funcapi_function_jobs",
78+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
79+
sa.Column("title", sa.String(), nullable=True),
80+
sa.Column("description", sa.String(), nullable=True),
81+
sa.Column("function_uuid", postgresql.UUID(as_uuid=True), nullable=False),
82+
sa.Column("function_class", sa.String(), nullable=True),
83+
sa.Column("status", sa.String(), nullable=True),
84+
sa.Column("inputs", sa.JSON(), nullable=True),
85+
sa.Column("outputs", sa.JSON(), nullable=True),
86+
sa.Column("class_specific_data", sa.JSON(), nullable=True),
87+
sa.Column(
88+
"created",
89+
sa.DateTime(timezone=True),
90+
server_default=sa.text("now()"),
91+
nullable=False,
92+
),
93+
sa.Column(
94+
"modified",
95+
sa.DateTime(timezone=True),
96+
server_default=sa.text("now()"),
97+
nullable=False,
98+
),
99+
sa.ForeignKeyConstraint(
100+
["function_uuid"],
101+
["funcapi_functions.uuid"],
102+
name="fk_function_jobs_to_function_uuid",
103+
onupdate="CASCADE",
104+
ondelete="CASCADE",
105+
),
106+
sa.PrimaryKeyConstraint("uuid", name="funcapi_function_jobs_pk"),
107+
)
108+
op.create_index(
109+
op.f("ix_funcapi_function_jobs_function_uuid"),
110+
"funcapi_function_jobs",
111+
["function_uuid"],
112+
unique=False,
113+
)
114+
op.create_index(
115+
op.f("ix_funcapi_function_jobs_uuid"),
116+
"funcapi_function_jobs",
117+
["uuid"],
118+
unique=False,
119+
)
120+
op.create_table(
121+
"funcapi_function_job_collections_to_function_jobs",
122+
sa.Column(
123+
"function_job_collection_uuid",
124+
postgresql.UUID(as_uuid=True),
125+
nullable=False,
126+
),
127+
sa.Column("function_job_uuid", postgresql.UUID(as_uuid=True), nullable=False),
128+
sa.Column(
129+
"created",
130+
sa.DateTime(timezone=True),
131+
server_default=sa.text("now()"),
132+
nullable=False,
133+
),
134+
sa.Column(
135+
"modified",
136+
sa.DateTime(timezone=True),
137+
server_default=sa.text("now()"),
138+
nullable=False,
139+
),
140+
sa.ForeignKeyConstraint(
141+
["function_job_collection_uuid"],
142+
["funcapi_function_job_collections.uuid"],
143+
name="fk_func_job_coll_to_func_jobs_to_func_job_coll_uuid",
144+
onupdate="CASCADE",
145+
ondelete="CASCADE",
146+
),
147+
sa.ForeignKeyConstraint(
148+
["function_job_uuid"],
149+
["funcapi_function_jobs.uuid"],
150+
name="fk_func_job_coll_to_func_jobs_to_func_job_uuid",
151+
onupdate="CASCADE",
152+
ondelete="CASCADE",
153+
),
154+
sa.PrimaryKeyConstraint(
155+
"function_job_collection_uuid",
156+
"function_job_uuid",
157+
name="funcapi_function_job_collections_to_function_jobs_pk",
158+
),
159+
)
160+
# ### end Alembic commands ###
161+
162+
163+
def downgrade():
164+
# ### commands auto generated by Alembic - please adjust! ###
165+
op.drop_table("funcapi_function_job_collections_to_function_jobs")
166+
op.drop_index(
167+
op.f("ix_funcapi_function_jobs_uuid"), table_name="funcapi_function_jobs"
168+
)
169+
op.drop_index(
170+
op.f("ix_funcapi_function_jobs_function_uuid"),
171+
table_name="funcapi_function_jobs",
172+
)
173+
op.drop_table("funcapi_function_jobs")
174+
op.drop_index(op.f("ix_funcapi_functions_uuid"), table_name="funcapi_functions")
175+
op.drop_table("funcapi_functions")
176+
op.drop_index(
177+
op.f("ix_funcapi_function_job_collections_uuid"),
178+
table_name="funcapi_function_job_collections",
179+
)
180+
op.drop_table("funcapi_function_job_collections")
181+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)