Skip to content

Commit 757f0b6

Browse files
authored
Split last migration to fix deadlock (#3330)
1 parent e76696c commit 757f0b6

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Add projects.original_name
2+
3+
Revision ID: 006512f572b4
4+
Revises: 06e977bc61c7
5+
Create Date: 2025-11-27 15:11:21.249079
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "006512f572b4"
14+
down_revision = "06e977bc61c7"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
# For postgres, this was moved from a previous migration to avoid deadlocks.
22+
# Keep SQLite in previous migration since it doesn't have deadlock issues and
23+
# does not support if_not_exists.
24+
if op.get_context().dialect.name != "sqlite":
25+
with op.batch_alter_table("projects", schema=None) as batch_op:
26+
batch_op.add_column(
27+
sa.Column("original_name", sa.String(length=50), nullable=True),
28+
if_not_exists=True,
29+
)
30+
# ### end Alembic commands ###
31+
32+
33+
def downgrade() -> None:
34+
# ### commands auto generated by Alembic - please adjust! ###
35+
if op.get_context().dialect.name != "sqlite":
36+
with op.batch_alter_table("projects", schema=None) as batch_op:
37+
batch_op.drop_column("original_name")
38+
# ### end Alembic commands ###

src/dstack/_internal/server/migrations/versions/06e977bc61c7_add_usermodel_deleted_and_original_name.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ def upgrade() -> None:
2424
)
2525
batch_op.add_column(sa.Column("original_name", sa.String(length=50), nullable=True))
2626

27-
with op.batch_alter_table("projects", schema=None) as batch_op:
28-
batch_op.add_column(sa.Column("original_name", sa.String(length=50), nullable=True))
27+
# For postgres, this was moved to a new migration to avoid deadlocks.
28+
if op.get_context().dialect.name == "sqlite":
29+
with op.batch_alter_table("projects", schema=None) as batch_op:
30+
batch_op.add_column(sa.Column("original_name", sa.String(length=50), nullable=True))
2931
# ### end Alembic commands ###
3032

3133

@@ -35,7 +37,9 @@ def downgrade() -> None:
3537
batch_op.drop_column("original_name")
3638
batch_op.drop_column("deleted")
3739

38-
with op.batch_alter_table("projects", schema=None) as batch_op:
39-
batch_op.drop_column("original_name")
40+
# For postgres, this was moved to a new migration to avoid deadlocks.
41+
if op.get_context().dialect.name == "sqlite":
42+
with op.batch_alter_table("projects", schema=None) as batch_op:
43+
batch_op.drop_column("original_name")
4044

4145
# ### end Alembic commands ###

0 commit comments

Comments
 (0)