Skip to content

Commit ea63903

Browse files
authored
Fix migration to check column existence before dropping (#101)
Make migration 2264546da1d9 idempotent by checking if columns exist before attempting to drop them. This prevents failures when columns don't exist, fixing the Init:CrashLoopBackOff issue in Kubernetes deployments.
1 parent 446609b commit ea63903

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

server/alembic/versions/2264546da1d9_simplify_alert_preferences.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020

2121
def upgrade() -> None:
2222
"""Upgrade schema."""
23-
# ### commands auto generated by Alembic - please adjust! ###
24-
with op.batch_alter_table('user_alert_preferences', schema=None) as batch_op:
25-
batch_op.drop_column('alert_types')
26-
batch_op.drop_column('email_min_severity')
27-
batch_op.drop_column('disaster_types')
23+
# Check if columns exist before dropping them (idempotent migration)
24+
conn = op.get_bind()
25+
inspector = sa.inspect(conn)
26+
columns = [col["name"] for col in inspector.get_columns("user_alert_preferences")]
2827

29-
# ### end Alembic commands ###
28+
with op.batch_alter_table('user_alert_preferences', schema=None) as batch_op:
29+
if "alert_types" in columns:
30+
batch_op.drop_column("alert_types")
31+
if "email_min_severity" in columns:
32+
batch_op.drop_column("email_min_severity")
33+
if "disaster_types" in columns:
34+
batch_op.drop_column("disaster_types")
3035

3136

3237
def downgrade() -> None:

0 commit comments

Comments
 (0)