feat: add index for run_id on messages and project_id on agents (#5117)

This commit is contained in:
Sarah Wooders
2025-10-03 14:37:13 -07:00
committed by Caren Thomas
parent d6bde22ab1
commit 65b33ae27f
3 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
"""create new runs table and remove legacy tables
Revision ID: 3bc3c031fbe4
Revises: 567e9fe06270
Create Date: 2025-10-03 12:10:51.065067
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "3bc3c031fbe4"
down_revision: Union[str, None] = "567e9fe06270"
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_agents_project_id", "agents", ["project_id"], unique=False)
op.create_index("ix_messages_run_id", "messages", ["run_id"], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_messages_run_id", table_name="messages")
op.drop_index("ix_agents_project_id", table_name="agents")
# ### end Alembic commands ###

View File

@@ -40,6 +40,7 @@ class Agent(SqlalchemyBase, OrganizationMixin, ProjectMixin, TemplateEntityMixin
Index("ix_agents_created_at", "created_at", "id"),
Index("ix_agents_organization_id", "organization_id"),
Index("ix_agents_organization_id_deployment_id", "organization_id", "deployment_id"),
Index("ix_agents_project_id", "project_id"),
)
# agent generates its own id

View File

@@ -21,6 +21,7 @@ class Message(SqlalchemyBase, OrganizationMixin, AgentMixin):
Index("ix_messages_created_at", "created_at", "id"),
Index("ix_messages_agent_sequence", "agent_id", "sequence_id"),
Index("ix_messages_org_agent", "organization_id", "agent_id"),
Index("ix_messages_run_id", "run_id"),
)
__pydantic_model__ = PydanticMessage