Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 6514110

Browse files
authored
Fixes migration to ensure index and column exist before dropping (#5456)
1 parent 8109845 commit 6514110

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/dispatch/database/revisions/tenant/versions/2024-11-04_928b725d64f6.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,28 @@ def upgrade():
3030
"entity", "source", existing_type=sa.BOOLEAN(), type_=sa.String(), existing_nullable=True
3131
)
3232

33-
op.drop_index("ix_entity_search_vector", table_name="entity", postgresql_using="gin")
34-
op.create_index(
35-
"entity_search_vector_idx",
36-
"entity",
37-
["search_vector"],
38-
unique=False,
39-
postgresql_using="gin",
40-
)
33+
indexes = inspector.get_indexes("entity")
34+
index_exists = any(index["name"] == "ix_entity_search_vector" for index in indexes)
35+
36+
if index_exists:
37+
op.drop_index("ix_entity_search_vector", table_name="entity", postgresql_using="gin")
38+
39+
index_exists = any(index["name"] == "entity_search_vector_idx" for index in indexes)
40+
if not index_exists:
41+
op.create_index(
42+
"entity_search_vector_idx",
43+
"entity",
44+
["search_vector"],
45+
unique=False,
46+
postgresql_using="gin",
47+
)
4148
op.alter_column("entity_type", "jpath", existing_type=sa.VARCHAR(), nullable=True)
42-
op.drop_column("plugin_instance", "configuration")
49+
50+
columns = inspector.get_columns("plugin_instance")
51+
column_exists = any(column["name"] == "configuration" for column in columns)
52+
if column_exists:
53+
op.drop_column("plugin_instance", "configuration")
54+
4355
op.drop_constraint("project_stable_priority_id_fkey", "project", type_="foreignkey")
4456
# ### end Alembic commands ###
4557

0 commit comments

Comments
 (0)