mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2025-09-02 02:30:07 +00:00
add workflow_permanent_id unique constraint and index to workflows table (#309)
This commit is contained in:
parent
b959822c6e
commit
a4ed6de34c
2 changed files with 60 additions and 3 deletions
|
@ -0,0 +1,40 @@
|
|||
"""Add workflow_permanent_id constraint and index to workflows table
|
||||
|
||||
Revision ID: baec12642d77
|
||||
Revises: bf561125112f
|
||||
Create Date: 2024-05-14 02:45:11.284376+00:00
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "baec12642d77"
|
||||
down_revision: Union[str, None] = "bf561125112f"
|
||||
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.alter_column("workflows", "workflow_permanent_id", existing_type=sa.VARCHAR(), nullable=False)
|
||||
op.alter_column("workflows", "version", existing_type=sa.INTEGER(), nullable=False)
|
||||
op.create_index(op.f("ix_workflows_workflow_permanent_id"), "workflows", ["workflow_permanent_id"], unique=False)
|
||||
op.create_index("permanent_id_version_idx", "workflows", ["workflow_permanent_id", "version"], unique=False)
|
||||
op.create_unique_constraint(
|
||||
"uc_org_permanent_id_version", "workflows", ["organization_id", "workflow_permanent_id", "version"]
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint("uc_org_permanent_id_version", "workflows", type_="unique")
|
||||
op.drop_index("permanent_id_version_idx", table_name="workflows")
|
||||
op.drop_index(op.f("ix_workflows_workflow_permanent_id"), table_name="workflows")
|
||||
op.alter_column("workflows", "version", existing_type=sa.INTEGER(), nullable=True)
|
||||
op.alter_column("workflows", "workflow_permanent_id", existing_type=sa.VARCHAR(), nullable=True)
|
||||
# ### end Alembic commands ###
|
|
@ -1,6 +1,19 @@
|
|||
import datetime
|
||||
|
||||
from sqlalchemy import JSON, Boolean, Column, DateTime, Enum, ForeignKey, Index, Integer, Numeric, String, UnicodeText
|
||||
from sqlalchemy import (
|
||||
JSON,
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
Enum,
|
||||
ForeignKey,
|
||||
Index,
|
||||
Integer,
|
||||
Numeric,
|
||||
String,
|
||||
UnicodeText,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.ext.asyncio import AsyncAttrs
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
|
@ -122,6 +135,10 @@ class ArtifactModel(Base):
|
|||
|
||||
class WorkflowModel(Base):
|
||||
__tablename__ = "workflows"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("organization_id", "workflow_permanent_id", "version", name="uc_org_permanent_id_version"),
|
||||
Index("permanent_id_version_idx", "workflow_permanent_id", "version"),
|
||||
)
|
||||
|
||||
workflow_id = Column(String, primary_key=True, index=True, default=generate_workflow_id)
|
||||
organization_id = Column(String, ForeignKey("organizations.organization_id"))
|
||||
|
@ -133,8 +150,8 @@ class WorkflowModel(Base):
|
|||
modified_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False)
|
||||
deleted_at = Column(DateTime, nullable=True)
|
||||
|
||||
workflow_permanent_id = Column(String, default=generate_workflow_permanent_id)
|
||||
version = Column(Integer, default=1)
|
||||
workflow_permanent_id = Column(String, nullable=False, default=generate_workflow_permanent_id, index=True)
|
||||
version = Column(Integer, default=1, nullable=False)
|
||||
|
||||
|
||||
class WorkflowRunModel(Base):
|
||||
|
|
Loading…
Add table
Reference in a new issue