Skip to content

Commit d5b1af6

Browse files
committed
Add index ix_volumes_pipeline_fetch_q
1 parent 4313220 commit d5b1af6

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Add ix_volumes_pipeline_fetch_q index
2+
3+
Revision ID: 9a363c3cbe04
4+
Revises: ccfac6ac7924
5+
Create Date: 2026-02-24 09:45:54.068288+00:00
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "9a363c3cbe04"
14+
down_revision = "ccfac6ac7924"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
with op.get_context().autocommit_block():
22+
op.drop_index(
23+
"ix_volumes_pipeline_fetch_q",
24+
table_name="volumes",
25+
if_exists=True,
26+
postgresql_concurrently=True,
27+
)
28+
op.create_index(
29+
"ix_volumes_pipeline_fetch_q",
30+
"volumes",
31+
[sa.literal_column("last_processed_at ASC")],
32+
unique=False,
33+
sqlite_where=sa.text("deleted = 0"),
34+
postgresql_where=sa.text("deleted IS FALSE"),
35+
postgresql_concurrently=True,
36+
)
37+
38+
# ### end Alembic commands ###
39+
40+
41+
def downgrade() -> None:
42+
# ### commands auto generated by Alembic - please adjust! ###
43+
with op.get_context().autocommit_block():
44+
op.drop_index(
45+
"ix_volumes_pipeline_fetch_q",
46+
table_name="volumes",
47+
if_exists=True,
48+
postgresql_concurrently=True,
49+
)
50+
# ### end Alembic commands ###

src/dstack/_internal/server/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,15 @@ class VolumeModel(PipelineModelMixin, BaseModel):
769769
# Deprecated in favor of VolumeAttachmentModel.attachment_data
770770
volume_attachment_data: Mapped[Optional[str]] = mapped_column(Text)
771771

772+
__table_args__ = (
773+
Index(
774+
"ix_volumes_pipeline_fetch_q",
775+
last_processed_at.asc(),
776+
postgresql_where=deleted == false(),
777+
sqlite_where=deleted == false(),
778+
),
779+
)
780+
772781

773782
class VolumeAttachmentModel(BaseModel):
774783
__tablename__ = "volumes_attachments"

0 commit comments

Comments
 (0)