Skip to content

Commit e032e1e

Browse files
committed
Add a new function db migration script
1 parent 267c7a5 commit e032e1e

File tree

1 file changed

+197
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)