Skip to content

Commit

Permalink
update script
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Jan 21, 2025
1 parent cb26397 commit 3a168e9
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 108 deletions.

This file was deleted.

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 ###

0 comments on commit 3a168e9

Please sign in to comment.