Skip to content

Commit e88e25f

Browse files
authored
Fix concurrent indexes migration (#3591)
1 parent 008efc8 commit e88e25f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/dstack/_internal/server/migrations/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def run_migrations(connection: Connection):
7373
# lock_timeout is needed so that migrations that acquire locks
7474
# do not wait for locks forever, blocking live queries.
7575
# Better to fail and retry a deployment.
76-
connection.execute(text("SET lock_timeout='10s';"))
76+
connection.execute(text("SET lock_timeout='15s';"))
7777
connection.commit()
7878
context.configure(
7979
connection=connection,

src/dstack/_internal/server/migrations/versions/2026/02_18_1122_a8ed24fd7f90_add_pipeline_indexes_for_compute_and_.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
def upgrade() -> None:
2020
# ### commands auto generated by Alembic - please adjust! ###
2121
with op.get_context().autocommit_block():
22+
if op.get_context().dialect.name == "postgresql":
23+
# Concurrent index ops can fail midway, leaving invalid indexes behind.
24+
# Use DROP INDEX IF EXISTS so the migration can be retried safely.
25+
op.drop_index(
26+
"ix_compute_groups_pipeline_fetch_q",
27+
table_name="compute_groups",
28+
if_exists=True,
29+
postgresql_concurrently=True,
30+
)
31+
op.drop_index(
32+
"ix_placement_groups_pipeline_fetch_q",
33+
table_name="placement_groups",
34+
if_exists=True,
35+
postgresql_concurrently=True,
36+
)
2237
op.create_index(
2338
"ix_compute_groups_pipeline_fetch_q",
2439
"compute_groups",
@@ -47,11 +62,13 @@ def downgrade() -> None:
4762
op.drop_index(
4863
"ix_placement_groups_pipeline_fetch_q",
4964
"placement_groups",
65+
if_exists=True,
5066
postgresql_concurrently=True,
5167
)
5268
op.drop_index(
5369
"ix_compute_groups_pipeline_fetch_q",
5470
"compute_groups",
71+
if_exists=True,
5572
postgresql_concurrently=True,
5673
)
5774
# ### end Alembic commands ###

0 commit comments

Comments
 (0)