diff --git a/src/dstack/_internal/server/migrations/env.py b/src/dstack/_internal/server/migrations/env.py index 81d8ba069..c7c27f1f8 100644 --- a/src/dstack/_internal/server/migrations/env.py +++ b/src/dstack/_internal/server/migrations/env.py @@ -73,7 +73,7 @@ def run_migrations(connection: Connection): # lock_timeout is needed so that migrations that acquire locks # do not wait for locks forever, blocking live queries. # Better to fail and retry a deployment. - connection.execute(text("SET lock_timeout='10s';")) + connection.execute(text("SET lock_timeout='15s';")) connection.commit() context.configure( connection=connection, diff --git a/src/dstack/_internal/server/migrations/versions/2026/02_18_1122_a8ed24fd7f90_add_pipeline_indexes_for_compute_and_.py b/src/dstack/_internal/server/migrations/versions/2026/02_18_1122_a8ed24fd7f90_add_pipeline_indexes_for_compute_and_.py index ad35a23d0..44cc2846e 100644 --- a/src/dstack/_internal/server/migrations/versions/2026/02_18_1122_a8ed24fd7f90_add_pipeline_indexes_for_compute_and_.py +++ b/src/dstack/_internal/server/migrations/versions/2026/02_18_1122_a8ed24fd7f90_add_pipeline_indexes_for_compute_and_.py @@ -19,6 +19,21 @@ def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### with op.get_context().autocommit_block(): + if op.get_context().dialect.name == "postgresql": + # Concurrent index ops can fail midway, leaving invalid indexes behind. + # Use DROP INDEX IF EXISTS so the migration can be retried safely. + op.drop_index( + "ix_compute_groups_pipeline_fetch_q", + table_name="compute_groups", + if_exists=True, + postgresql_concurrently=True, + ) + op.drop_index( + "ix_placement_groups_pipeline_fetch_q", + table_name="placement_groups", + if_exists=True, + postgresql_concurrently=True, + ) op.create_index( "ix_compute_groups_pipeline_fetch_q", "compute_groups", @@ -47,11 +62,13 @@ def downgrade() -> None: op.drop_index( "ix_placement_groups_pipeline_fetch_q", "placement_groups", + if_exists=True, postgresql_concurrently=True, ) op.drop_index( "ix_compute_groups_pipeline_fetch_q", "compute_groups", + if_exists=True, postgresql_concurrently=True, ) # ### end Alembic commands ###