Skip to content

Commit

Permalink
fix index
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai committed Oct 18, 2023
1 parent c9296d7 commit f97e082
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions migrations/versions/0439_add_index_n_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@
down_revision = "0438_sms_templates_msgs_left"


def index_exists(name):
connection = op.get_bind()
result = connection.execute(
"SELECT exists(SELECT 1 from pg_indexes where indexname = '{}') as ix_exists;".format(name)
).first()
return result.ix_exists


# option 1
def upgrade():
op.execute("COMMIT")
op.create_index(
op.f("ix_notification_history_created_by_id"), "notification_history", ["created_by_id"], postgresql_concurrently=True
)
if not index_exists("ix_notification_history_created_by_id"):
op.create_index(
op.f("ix_notification_history_created_by_id"), "notification_history", ["created_by_id"], postgresql_concurrently=True
)


def downgrade():
Expand Down

0 comments on commit f97e082

Please sign in to comment.