Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow run block #1332

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Introduce workflow_run_blocks

Revision ID: 7581e473eaf1
Revises: db41106b9f1a
Create Date: 2024-12-06 00:48:39.821275+00:00

"""

from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "7581e473eaf1"
down_revision: Union[str, None] = "db41106b9f1a"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"workflow_run_blocks",
sa.Column("workflow_run_block_id", sa.String(), nullable=False),
sa.Column("workflow_run_id", sa.String(), nullable=False),
sa.Column("parent_workflow_run_block_id", sa.String(), nullable=True),
sa.Column("organization_id", sa.String(), nullable=True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making 'organization_id' non-nullable or revising the index 'wfrb_org_wfr_index' to handle nullable columns appropriately.

sa.Column("task_id", sa.String(), nullable=True),
sa.Column("label", sa.String(), nullable=False),
sa.Column("block_type", sa.String(), nullable=False),
sa.Column("status", sa.String(), nullable=False),
sa.Column("output", sa.JSON(), nullable=True),
sa.Column("continue_on_failure", sa.Boolean(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.organization_id"],
),
sa.ForeignKeyConstraint(
["parent_workflow_run_block_id"],
["workflow_run_blocks.workflow_run_block_id"],
),
sa.ForeignKeyConstraint(
["task_id"],
["tasks.task_id"],
),
sa.ForeignKeyConstraint(
["workflow_run_id"],
["workflow_runs.workflow_run_id"],
),
sa.PrimaryKeyConstraint("workflow_run_block_id"),
)
op.create_index("wfrb_org_wfr_index", "workflow_run_blocks", ["organization_id", "workflow_run_id"], unique=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("wfrb_org_wfr_index", table_name="workflow_run_blocks")
op.drop_table("workflow_run_blocks")
# ### end Alembic commands ###
6 changes: 6 additions & 0 deletions skyvern/forge/sdk/db/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
WORKFLOW_PREFIX = "w"
WORKFLOW_PERMANENT_ID_PREFIX = "wpid"
WORKFLOW_RUN_PREFIX = "wr"
WORKFLOW_RUN_BLOCK_PREFIX = "wrb"
WORKFLOW_PARAMETER_PREFIX = "wp"
AWS_SECRET_PARAMETER_PREFIX = "asp"
OUTPUT_PARAMETER_PREFIX = "op"
Expand All @@ -55,6 +56,11 @@ def generate_workflow_permanent_id() -> str:
return f"{WORKFLOW_PERMANENT_ID_PREFIX}_{int_id}"


def generate_workflow_run_block_id() -> str:
int_id = generate_id()
return f"{WORKFLOW_RUN_BLOCK_PREFIX}_{int_id}"
wintonzheng marked this conversation as resolved.
Show resolved Hide resolved


def generate_workflow_run_id() -> str:
int_id = generate_id()
return f"{WORKFLOW_RUN_PREFIX}_{int_id}"
Expand Down
22 changes: 22 additions & 0 deletions skyvern/forge/sdk/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
generate_workflow_id,
generate_workflow_parameter_id,
generate_workflow_permanent_id,
generate_workflow_run_block_id,
generate_workflow_run_id,
)
from skyvern.forge.sdk.schemas.tasks import ProxyLocation
Expand Down Expand Up @@ -473,3 +474,24 @@ class ActionModel(Base):

created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
modified_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False)


class WorkflowRunBlockModel(Base):
__tablename__ = "workflow_run_blocks"
__table_args__ = (Index("wfrb_org_wfr_index", "organization_id", "workflow_run_id"),)

workflow_run_block_id = Column(String, primary_key=True, default=generate_workflow_run_block_id)
workflow_run_id = Column(String, ForeignKey("workflow_runs.workflow_run_id"), nullable=False)
parent_workflow_run_block_id = Column(
String, ForeignKey("workflow_run_blocks.workflow_run_block_id"), nullable=True
)
organization_id = Column(String, ForeignKey("organizations.organization_id"), nullable=True)
task_id = Column(String, ForeignKey("tasks.task_id"), nullable=True)
label = Column(String, nullable=False)
block_type = Column(String, nullable=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using an Enum for the block_type field to ensure consistency and prevent invalid block type values.

status = Column(String, nullable=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using an Enum for the status field to ensure consistency and validation. This is applicable in other models as well where status is used as a String (e.g., TaskModel, StepModel, WorkflowRunModel).

output = Column(JSON, nullable=True)
continue_on_failure = Column(Boolean, nullable=False, default=False)

created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using timezone-aware datetime for created_at and modified_at fields for consistency and to avoid potential issues with timezones.

modified_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False)
Loading