Skip to content

Commit 49415a5

Browse files
add columns
1 parent d0f989e commit 49415a5

File tree

3 files changed

+149
-141
lines changed

3 files changed

+149
-141
lines changed

packages/postgres-database/src/simcore_postgres_database/migration/versions/1d74a6de5e36_move_projects_workbench.py

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""Move projects workbench
2+
3+
Revision ID: 876bae5ff8da
4+
Revises: 307017ee1a49
5+
Create Date: 2025-01-08 10:43:50.901038+00:00
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from sqlalchemy.dialects import postgresql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '876bae5ff8da'
14+
down_revision = '307017ee1a49'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('projects_nodes', sa.Column('key', sa.String(), nullable=False))
22+
op.add_column('projects_nodes', sa.Column('version', sa.String(), nullable=False))
23+
op.add_column('projects_nodes', sa.Column('label', sa.String(), nullable=False))
24+
op.add_column('projects_nodes', sa.Column('progress', sa.Numeric(), nullable=True))
25+
op.add_column('projects_nodes', sa.Column('thumbnail', sa.String(), nullable=True))
26+
op.add_column('projects_nodes', sa.Column('input_access', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
27+
op.add_column('projects_nodes', sa.Column('input_nodes', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
28+
op.add_column('projects_nodes', sa.Column('inputs', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
29+
op.add_column('projects_nodes', sa.Column('inputs_units', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
30+
op.add_column('projects_nodes', sa.Column('output_nodes', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
31+
op.add_column('projects_nodes', sa.Column('outputs', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
32+
op.add_column('projects_nodes', sa.Column('run_hash', sa.String(), nullable=True))
33+
op.add_column('projects_nodes', sa.Column('state', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
34+
op.add_column('projects_nodes', sa.Column('parent', sa.String(), nullable=True))
35+
op.add_column('projects_nodes', sa.Column('boot_options', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
36+
# ### end Alembic commands ###
37+
38+
# Populate the new columns with data from the workbench
39+
op.execute(
40+
"""
41+
UPDATE projects_nodes
42+
SET key = subquery.key,
43+
version = subquery.version,
44+
label = subquery.label,
45+
progress = subquery.progress::numeric,
46+
thumbnail = subquery.thumbnail,
47+
input_access = subquery.input_access::jsonb,
48+
input_nodes = subquery.input_nodes::jsonb,
49+
inputs = subquery.inputs::jsonb,
50+
inputs_units = subquery.inputs_units::jsonb,
51+
outpuy_nodes = subquery.output_nodes::jsonb,
52+
outputs = subquery.outputs::jsonb,
53+
run_hash = subquery.run_hash,
54+
state = subquery.state::jsonb
55+
parent = subquery.parent,
56+
boot_options = subquery.boot_options::jsonb
57+
FROM (
58+
SELECT
59+
projects.uuid AS project_id,
60+
js.key AS node_id,
61+
js.value::jsonb ->> 'key' AS key,
62+
js.value::jsonb ->> 'label' AS label,
63+
js.value::jsonb ->> 'version' AS version,
64+
(js.value::jsonb ->> 'progress')::numeric AS progress,
65+
js.value::jsonb ->> 'thumbnail' AS thumbnail,
66+
js.value::jsonb ->> 'inputAccess' AS input_access,
67+
js.value::jsonb ->> 'inputNodes' AS input_nodes,
68+
js.value::jsonb ->> 'inputs' AS inputs,
69+
js.value::jsonb ->> 'inputsUnits' AS inputs_units,
70+
js.value::jsonb ->> 'outputNodes' AS output_nodes,
71+
js.value::jsonb ->> 'outputs' AS outputs,
72+
js.value::jsonb ->> 'runHash' AS run_hash,
73+
js.value::jsonb ->> 'state' AS state
74+
js.value::jsonb ->> 'parent' AS parent,
75+
js.value::jsonb ->> 'bootOptions' AS boot_options
76+
FROM projects,
77+
json_each(projects.workbench) AS js
78+
) AS subquery
79+
WHERE projects_nodes.project_uuid = subquery.project_id
80+
AND projects_nodes.node_id = subquery.node_id;
81+
"""
82+
)
83+
op.alter_column("projects_nodes", "key", nullable=False)
84+
op.alter_column("projects_nodes", "version", nullable=False)
85+
op.alter_column("projects_nodes", "label", nullable=False)
86+
87+
def downgrade():
88+
# ### commands auto generated by Alembic - please adjust! ###
89+
op.drop_column('projects_nodes', 'boot_options')
90+
op.drop_column('projects_nodes', 'parent')
91+
op.drop_column('projects_nodes', 'state')
92+
op.drop_column('projects_nodes', 'run_hash')
93+
op.drop_column('projects_nodes', 'outputs')
94+
op.drop_column('projects_nodes', 'output_nodes')
95+
op.drop_column('projects_nodes', 'inputs_units')
96+
op.drop_column('projects_nodes', 'inputs')
97+
op.drop_column('projects_nodes', 'input_nodes')
98+
op.drop_column('projects_nodes', 'input_access')
99+
op.drop_column('projects_nodes', 'thumbnail')
100+
op.drop_column('projects_nodes', 'progress')
101+
op.drop_column('projects_nodes', 'label')
102+
op.drop_column('projects_nodes', 'version')
103+
op.drop_column('projects_nodes', 'key')
104+
# ### end Alembic commands ###

packages/postgres-database/src/simcore_postgres_database/models/projects_nodes.py

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,48 @@
8787
nullable=True,
8888
doc="Url of the latest screenshot of the node",
8989
),
90+
sa.Column(
91+
"input_access",
92+
JSONB,
93+
nullable=True,
94+
doc="Map with key - access level pairs",
95+
),
96+
sa.Column(
97+
"input_nodes",
98+
JSONB, # Array
99+
nullable=True,
100+
doc="Node IDs of where the node is connected to",
101+
),
90102
sa.Column(
91103
"inputs",
92104
JSONB,
93105
nullable=True,
94-
doc="Values of input properties",
106+
doc="Input properties values",
107+
),
108+
sa.Column(
109+
"inputs_units",
110+
JSONB,
111+
nullable=True,
112+
doc="Input unit values",
113+
),
114+
sa.Column(
115+
"output_nodes",
116+
JSONB, # Array
117+
nullable=True,
118+
doc="Node IDs of those connected to the output",
95119
),
96120
sa.Column(
97121
"outputs",
98122
JSONB,
99123
nullable=True,
100-
doc="Values of output properties",
124+
doc="Output properties values",
101125
),
126+
# sa.Column(
127+
# "output_node",
128+
# sa.BOOLEAN,
129+
# nullable=True,
130+
# doc="Deprecated",
131+
# ),
102132
sa.Column(
103133
"run_hash",
104134
sa.String,
@@ -111,60 +141,25 @@
111141
nullable=True,
112142
doc="Node state",
113143
),
114-
# sa.Column(
115-
# "inputs_units",
116-
# JSONB,
117-
# nullable=False,
118-
# server_default=sa.text("'{}'::jsonb"),
119-
# doc="Values of input unit",
120-
# ),
121-
# sa.Column(
122-
# "input_access",
123-
# JSONB,
124-
# nullable=False,
125-
# server_default=sa.text("'{}'::jsonb"),
126-
# doc="Map with key - access level pairs",
127-
# ),
128-
# sa.Column(
129-
# "input_nodes",
130-
# JSONB, # <-- ARRAY
131-
# nullable=False,
132-
# server_default=sa.text("'[]'::jsonb"),
133-
# doc="Node IDs of where the node is connected to",
134-
# ),
135-
# sa.Column(
136-
# "output_node",
137-
# sa.BOOLEAN,
138-
# nullable=False,
139-
# doc="Deprecated",
140-
# ),
141-
# sa.Column(
142-
# "output_nodes",
143-
# JSONB, # <-- ARRAY
144-
# nullable=False,
145-
# server_default=sa.text("'[]'::jsonb"),
146-
# doc="Used in group-nodes. Node IDs of those connected to the output",
147-
# ),
148-
# sa.Column(
149-
# "parent",
150-
# sa.String,
151-
# nullable=True,
152-
# doc="Parent's (group-nodes) node IDs.",
153-
# ),
144+
sa.Column(
145+
"parent",
146+
sa.String,
147+
nullable=True,
148+
doc="Parent's (group-nodes) node ID",
149+
),
154150
# sa.Column(
155151
# "position",
156152
# JSONB,
157153
# nullable=True,
158-
# server_default=sa.text("'{}'::jsonb"),
159154
# doc="Deprecated",
160155
# ),
161-
# sa.Column(
162-
# "boot_options",
163-
# JSONB,
164-
# nullable=True,
165-
# server_default=sa.text("'{}'::jsonb"),
166-
# doc="Some services provide alternative parameters to be injected at boot time. The user selection should be stored here, and it will overwrite the services's defaults.",
167-
# ),
156+
sa.Column(
157+
"boot_options",
158+
JSONB,
159+
nullable=True,
160+
doc="Some services provide alternative parameters to be injected at boot time."
161+
"The user selection should be stored here, and it will overwrite the services's defaults",
162+
),
168163
sa.UniqueConstraint("project_uuid", "node_id"),
169164
)
170165

0 commit comments

Comments
 (0)