Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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,45 @@
"""Add ix_runs_project_id_submitted_at_id

Revision ID: bb3f3be7c111
Revises: 2d2692d5b3c2
Create Date: 2026-11-24 06:25:56.558461+00:00

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "bb3f3be7c111"
down_revision = "2d2692d5b3c2"
branch_labels = None
depends_on = None

TABLE_NAME = "runs"
INDEX_NAME = "ix_runs_project_id_submitted_at_id"


def _drop_index() -> None:
op.drop_index(
INDEX_NAME,
table_name=TABLE_NAME,
if_exists=True,
postgresql_concurrently=True,
)


def upgrade() -> None:
with op.get_context().autocommit_block():
_drop_index()
op.create_index(
INDEX_NAME,
TABLE_NAME,
["project_id", sa.text("submitted_at DESC"), "id"],
unique=False,
postgresql_concurrently=True,
)


def downgrade() -> None:
with op.get_context().autocommit_block():
_drop_index()
1 change: 1 addition & 0 deletions src/dstack/_internal/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ class RunModel(PipelineModelMixin, BaseModel):

__table_args__ = (
Index("ix_submitted_at_id", submitted_at.desc(), id),
Index("ix_runs_project_id_submitted_at_id", project_id, submitted_at.desc(), id),
Index(
"ix_runs_pipeline_fetch_q",
last_processed_at.asc(),
Expand Down
Loading