-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
272671c
commit 6e92682
Showing
51 changed files
with
673 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
227 changes: 227 additions & 0 deletions
227
...src/simcore_postgres_database/migration/versions/ecd4eadaa781_extract_workbench_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
"""extract workbench column | ||
Revision ID: ecd4eadaa781 | ||
Revises: a3a58471b0f1 | ||
Create Date: 2025-01-21 13:13:18.256109+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ecd4eadaa781" | ||
down_revision = "a3a58471b0f1" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"key", | ||
sa.String(), | ||
nullable=False, | ||
comment="Distinctive name (based on the Docker registry path)", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"version", sa.String(), nullable=False, comment="Semantic version number" | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"label", sa.String(), nullable=False, comment="Short name used for display" | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"progress", sa.Numeric(), nullable=True, comment="Progress value (0-100)" | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"thumbnail", | ||
sa.String(), | ||
nullable=True, | ||
comment="Url of the latest screenshot", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"input_access", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="Map with key - access level pairs", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"input_nodes", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="IDs of the nodes where is connected to", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"inputs", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="Input properties values", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"inputs_required", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="Required input IDs", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"inputs_units", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="Input units", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"output_nodes", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="Node IDs of those connected to the output", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"outputs", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="Output properties values", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"run_hash", | ||
sa.String(), | ||
nullable=True, | ||
comment="HEX digest of the resolved inputs + outputs hash at the time when the last outputs were generated", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"state", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="State", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"parent", | ||
sa.String(), | ||
nullable=True, | ||
comment="Parent's (group-nodes) node ID", | ||
), | ||
) | ||
op.add_column( | ||
"projects_nodes", | ||
sa.Column( | ||
"boot_options", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
comment="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", | ||
), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
op.execute( | ||
""" | ||
UPDATE projects_nodes | ||
SET key = subquery.key, | ||
version = subquery.version, | ||
label = subquery.label, | ||
progress = subquery.progress::numeric, | ||
thumbnail = subquery.thumbnail, | ||
input_access = subquery.input_access::jsonb, | ||
input_nodes = subquery.input_nodes::jsonb, | ||
inputs = subquery.inputs::jsonb, | ||
inputs_required = subquery.inputs_required::jsonb, | ||
inputs_units = subquery.inputs_units::jsonb, | ||
output_nodes = subquery.output_nodes::jsonb, | ||
outputs = subquery.outputs::jsonb, | ||
run_hash = subquery.run_hash, | ||
state = subquery.state::jsonb, | ||
parent = subquery.parent, | ||
boot_options = subquery.boot_options::jsonb | ||
FROM ( | ||
SELECT | ||
projects.uuid AS project_id, | ||
js.key AS node_id, | ||
js.value::jsonb ->> 'key' AS key, | ||
js.value::jsonb ->> 'label' AS label, | ||
js.value::jsonb ->> 'version' AS version, | ||
(js.value::jsonb ->> 'progress')::numeric AS progress, | ||
js.value::jsonb ->> 'thumbnail' AS thumbnail, | ||
js.value::jsonb ->> 'inputAccess' AS input_access, | ||
js.value::jsonb ->> 'inputNodes' AS input_nodes, | ||
js.value::jsonb ->> 'inputs' AS inputs, | ||
js.value::jsonb ->> 'inputsRequired' AS inputs_required, | ||
js.value::jsonb ->> 'inputsUnits' AS inputs_units, | ||
js.value::jsonb ->> 'outputNodes' AS output_nodes, | ||
js.value::jsonb ->> 'outputs' AS outputs, | ||
js.value::jsonb ->> 'runHash' AS run_hash, | ||
js.value::jsonb ->> 'state' AS state, | ||
js.value::jsonb ->> 'parent' AS parent, | ||
js.value::jsonb ->> 'bootOptions' AS boot_options | ||
FROM projects, | ||
json_each(projects.workbench) AS js | ||
) AS subquery | ||
WHERE projects_nodes.project_uuid = subquery.project_id | ||
AND projects_nodes.node_id = subquery.node_id; | ||
""" | ||
) | ||
op.alter_column("projects_nodes", "key", nullable=False) | ||
op.alter_column("projects_nodes", "version", nullable=False) | ||
op.alter_column("projects_nodes", "label", nullable=False) | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("projects_nodes", "boot_options") | ||
op.drop_column("projects_nodes", "parent") | ||
op.drop_column("projects_nodes", "state") | ||
op.drop_column("projects_nodes", "run_hash") | ||
op.drop_column("projects_nodes", "outputs") | ||
op.drop_column("projects_nodes", "output_nodes") | ||
op.drop_column("projects_nodes", "inputs_units") | ||
op.drop_column("projects_nodes", "inputs_required") | ||
op.drop_column("projects_nodes", "inputs") | ||
op.drop_column("projects_nodes", "input_nodes") | ||
op.drop_column("projects_nodes", "input_access") | ||
op.drop_column("projects_nodes", "thumbnail") | ||
op.drop_column("projects_nodes", "progress") | ||
op.drop_column("projects_nodes", "label") | ||
op.drop_column("projects_nodes", "version") | ||
op.drop_column("projects_nodes", "key") | ||
# ### end Alembic commands ### |
Oops, something went wrong.