From 81f1317381b9d35eaa4d460187bff3b5d9cc7968 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Thu, 25 Sep 2025 08:09:47 -0700 Subject: [PATCH] index for created_at for multiple tables (#3526) --- ...dd_created_at_index_for_multiple_tables.py | 43 +++++++++++++++++++ skyvern/forge/sdk/db/models.py | 17 ++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 alembic/versions/2025_09_25_1503-e0ccabc005af_add_created_at_index_for_multiple_tables.py diff --git a/alembic/versions/2025_09_25_1503-e0ccabc005af_add_created_at_index_for_multiple_tables.py b/alembic/versions/2025_09_25_1503-e0ccabc005af_add_created_at_index_for_multiple_tables.py new file mode 100644 index 00000000..9814b319 --- /dev/null +++ b/alembic/versions/2025_09_25_1503-e0ccabc005af_add_created_at_index_for_multiple_tables.py @@ -0,0 +1,43 @@ +"""add created_at index for multiple tables + +Revision ID: e0ccabc005af +Revises: 4925c34e8d58 +Create Date: 2025-09-25 15:03:25.567938+00:00 + +""" + +from typing import Sequence, Union + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "e0ccabc005af" +down_revision: Union[str, None] = "4925c34e8d58" +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( + "ix_observer_cruises_org_created_at", "observer_cruises", ["organization_id", "created_at"], unique=False + ) + op.create_index( + "ix_observer_thoughts_org_created_at", "observer_thoughts", ["organization_id", "created_at"], unique=False + ) + op.create_index("ix_task_runs_org_created_at", "task_runs", ["organization_id", "created_at"], unique=False) + op.create_index("ix_totp_codes_org_created_at", "totp_codes", ["organization_id", "created_at"], unique=False) + op.create_index( + "ix_workflow_run_blocks_org_created_at", "workflow_run_blocks", ["organization_id", "created_at"], unique=False + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index("ix_workflow_run_blocks_org_created_at", table_name="workflow_run_blocks") + op.drop_index("ix_totp_codes_org_created_at", table_name="totp_codes") + op.drop_index("ix_task_runs_org_created_at", table_name="task_runs") + op.drop_index("ix_observer_thoughts_org_created_at", table_name="observer_thoughts") + op.drop_index("ix_observer_cruises_org_created_at", table_name="observer_cruises") + # ### end Alembic commands ### diff --git a/skyvern/forge/sdk/db/models.py b/skyvern/forge/sdk/db/models.py index 57934b84..64b5854c 100644 --- a/skyvern/forge/sdk/db/models.py +++ b/skyvern/forge/sdk/db/models.py @@ -573,6 +573,7 @@ class AISuggestionModel(Base): class TOTPCodeModel(Base): __tablename__ = "totp_codes" + __table_args__ = (Index("ix_totp_codes_org_created_at", "organization_id", "created_at"),) totp_code_id = Column(String, primary_key=True, default=generate_totp_code_id) totp_identifier = Column(String, nullable=False, index=True) @@ -622,7 +623,10 @@ class ActionModel(Base): class WorkflowRunBlockModel(Base): __tablename__ = "workflow_run_blocks" - __table_args__ = (Index("wfrb_org_wfr_index", "organization_id", "workflow_run_id"),) + __table_args__ = ( + Index("wfrb_org_wfr_index", "organization_id", "workflow_run_id"), + Index("ix_workflow_run_blocks_org_created_at", "organization_id", "created_at"), + ) workflow_run_block_id = Column(String, primary_key=True, default=generate_workflow_run_block_id) workflow_run_id = Column(String, nullable=False) @@ -672,7 +676,10 @@ class WorkflowRunBlockModel(Base): class TaskV2Model(Base): __tablename__ = "observer_cruises" - __table_args__ = (Index("oc_org_wfr_index", "organization_id", "workflow_run_id"),) + __table_args__ = ( + Index("oc_org_wfr_index", "organization_id", "workflow_run_id"), + Index("ix_observer_cruises_org_created_at", "organization_id", "created_at"), + ) # observer_cruise_id is the task_id for task v2 observer_cruise_id = Column(String, primary_key=True, default=generate_task_v2_id) @@ -710,7 +717,10 @@ class TaskV2Model(Base): class ThoughtModel(Base): __tablename__ = "observer_thoughts" - __table_args__ = (Index("observer_cruise_index", "organization_id", "observer_cruise_id"),) + __table_args__ = ( + Index("observer_cruise_index", "organization_id", "observer_cruise_id"), + Index("ix_observer_thoughts_org_created_at", "organization_id", "created_at"), + ) observer_thought_id = Column(String, primary_key=True, default=generate_thought_id) organization_id = Column(String, nullable=True) @@ -763,6 +773,7 @@ class TaskRunModel(Base): __table_args__ = ( Index("task_run_org_url_index", "organization_id", "url_hash", "cached"), Index("task_run_org_run_id_index", "organization_id", "run_id"), + Index("ix_task_runs_org_created_at", "organization_id", "created_at"), ) task_run_id = Column(String, primary_key=True, default=generate_task_run_id)