From 04d568541a0534a45f3c9a27bc11dd74b9a7d440 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Mon, 2 Dec 2024 09:25:13 -0800 Subject: [PATCH] created_at index for steps table (#1301) --- ...1a_steps_db_change_add_created_at_index.py | 29 +++++++++++++++++++ skyvern/forge/sdk/db/models.py | 5 +++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 alembic/versions/2024_12_02_1609-db41106b9f1a_steps_db_change_add_created_at_index.py diff --git a/alembic/versions/2024_12_02_1609-db41106b9f1a_steps_db_change_add_created_at_index.py b/alembic/versions/2024_12_02_1609-db41106b9f1a_steps_db_change_add_created_at_index.py new file mode 100644 index 0000000000..f9303e6ecc --- /dev/null +++ b/alembic/versions/2024_12_02_1609-db41106b9f1a_steps_db_change_add_created_at_index.py @@ -0,0 +1,29 @@ +"""steps DB change: add created_at index + +Revision ID: db41106b9f1a +Revises: a5feab7712fe +Create Date: 2024-12-02 16:09:57.679626+00:00 + +""" + +from typing import Sequence, Union + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "db41106b9f1a" +down_revision: Union[str, None] = "a5feab7712fe" +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_index("created_at_org_index", "steps", ["created_at", "organization_id"], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index("created_at_org_index", table_name="steps") + # ### end Alembic commands ### diff --git a/skyvern/forge/sdk/db/models.py b/skyvern/forge/sdk/db/models.py index 1fbe81f348..1c1d3b68fa 100644 --- a/skyvern/forge/sdk/db/models.py +++ b/skyvern/forge/sdk/db/models.py @@ -84,7 +84,10 @@ class TaskModel(Base): class StepModel(Base): __tablename__ = "steps" - __table_args__ = (Index("org_task_index", "organization_id", "task_id"),) + __table_args__ = ( + Index("org_task_index", "organization_id", "task_id"), + Index("created_at_org_index", "created_at", "organization_id"), + ) step_id = Column(String, primary_key=True, index=True, default=generate_step_id) organization_id = Column(String, ForeignKey("organizations.organization_id"))