Skip to content

Commit 080e4fb

Browse files
committed
Add db migration script for functions api
1 parent 1b1e8fe commit 080e4fb

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
"""Add function tables
2+
3+
Revision ID: 93dbd49553ae
4+
Revises: cf8f743fd0b7
5+
Create Date: 2025-04-16 09:32:48.976846+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 = "93dbd49553ae"
15+
down_revision = "cf8f743fd0b7"
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+
"function_job_collections",
24+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
25+
sa.Column("name", sa.String(), nullable=True),
26+
sa.PrimaryKeyConstraint("uuid", name="function_job_collections_pk"),
27+
)
28+
op.create_index(
29+
op.f("ix_function_job_collections_uuid"),
30+
"function_job_collections",
31+
["uuid"],
32+
unique=False,
33+
)
34+
op.create_table(
35+
"functions",
36+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
37+
sa.Column("title", sa.String(), nullable=True),
38+
sa.Column("function_class", sa.String(), nullable=True),
39+
sa.Column("description", sa.String(), nullable=True),
40+
sa.Column("input_schema", sa.JSON(), nullable=True),
41+
sa.Column("output_schema", sa.JSON(), nullable=True),
42+
sa.Column("system_tags", sa.JSON(), nullable=True),
43+
sa.Column("user_tags", sa.JSON(), nullable=True),
44+
sa.Column("class_specific_data", sa.JSON(), nullable=True),
45+
sa.PrimaryKeyConstraint("uuid", name="functions_pk"),
46+
)
47+
op.create_index(op.f("ix_functions_uuid"), "functions", ["uuid"], unique=False)
48+
op.create_table(
49+
"function_jobs",
50+
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
51+
sa.Column("title", sa.String(), nullable=True),
52+
sa.Column("function_uuid", postgresql.UUID(as_uuid=True), nullable=False),
53+
sa.Column("function_class", sa.String(), nullable=True),
54+
sa.Column("status", sa.String(), nullable=True),
55+
sa.Column("inputs", sa.JSON(), nullable=True),
56+
sa.Column("outputs", sa.JSON(), nullable=True),
57+
sa.Column("class_specific_data", sa.JSON(), nullable=True),
58+
sa.ForeignKeyConstraint(
59+
["function_uuid"],
60+
["functions.uuid"],
61+
name="fk_functions_to_function_jobs_to_function_uuid",
62+
onupdate="CASCADE",
63+
ondelete="CASCADE",
64+
),
65+
sa.PrimaryKeyConstraint("uuid", name="function_jobs_pk"),
66+
)
67+
op.create_index(
68+
op.f("ix_function_jobs_function_uuid"),
69+
"function_jobs",
70+
["function_uuid"],
71+
unique=False,
72+
)
73+
op.create_index(
74+
op.f("ix_function_jobs_uuid"), "function_jobs", ["uuid"], unique=False
75+
)
76+
op.create_table(
77+
"function_job_collections_to_function_jobs",
78+
sa.Column(
79+
"function_job_collection_uuid", postgresql.UUID(as_uuid=True), nullable=True
80+
),
81+
sa.Column("function_job_uuid", postgresql.UUID(as_uuid=True), nullable=True),
82+
sa.ForeignKeyConstraint(
83+
["function_job_collection_uuid"],
84+
["function_job_collections.uuid"],
85+
name="fk_func_job_coll_to_func_jobs_to_func_job_coll_uuid",
86+
onupdate="CASCADE",
87+
ondelete="CASCADE",
88+
),
89+
sa.ForeignKeyConstraint(
90+
["function_job_uuid"],
91+
["function_jobs.uuid"],
92+
name="fk_func_job_coll_to_func_jobs_to_func_job_uuid",
93+
onupdate="CASCADE",
94+
ondelete="CASCADE",
95+
),
96+
)
97+
op.drop_index("idx_projects_last_change_date_desc", table_name="projects")
98+
op.create_index(
99+
"idx_projects_last_change_date_desc",
100+
"projects",
101+
["last_change_date"],
102+
unique=False,
103+
postgresql_using="btree",
104+
postgresql_ops={"last_change_date": "DESC"},
105+
)
106+
# ### end Alembic commands ###
107+
108+
109+
def downgrade():
110+
# ### commands auto generated by Alembic - please adjust! ###
111+
op.drop_index(
112+
"idx_projects_last_change_date_desc",
113+
table_name="projects",
114+
postgresql_using="btree",
115+
postgresql_ops={"last_change_date": "DESC"},
116+
)
117+
op.create_index(
118+
"idx_projects_last_change_date_desc",
119+
"projects",
120+
[sa.text("last_change_date DESC")],
121+
unique=False,
122+
)
123+
op.drop_table("function_job_collections_to_function_jobs")
124+
op.drop_index(op.f("ix_function_jobs_uuid"), table_name="function_jobs")
125+
op.drop_index(op.f("ix_function_jobs_function_uuid"), table_name="function_jobs")
126+
op.drop_table("function_jobs")
127+
op.drop_index(op.f("ix_functions_uuid"), table_name="functions")
128+
op.drop_table("functions")
129+
op.drop_index(
130+
op.f("ix_function_job_collections_uuid"), table_name="function_job_collections"
131+
)
132+
op.drop_table("function_job_collections")
133+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)