Skip to content

Commit

Permalink
Added postgres support
Browse files Browse the repository at this point in the history
  • Loading branch information
hirensoni913 committed Jun 6, 2024
1 parent cba04a4 commit 8cdb30c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/services/utils/remove_indexes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import connection, migrations
import os


class RemoveIndexForField(migrations.RunPython):
Expand All @@ -16,7 +17,10 @@ def remove_index(self, app, schema_editor):
constraints = connection.introspection.get_constraints(cursor, model._meta.db_table)
for constraint_name, constraint_info in constraints.items():
if constraint_info["index"] and any(field.column.lower() == col.lower() for col in constraint_info["columns"]):
cursor.execute(f"DROP INDEX {constraint_name} ON {model._meta.db_table}")
if os.environ.get("DB_DEFAULT") == 'mssql':
cursor.execute(f"DROP INDEX {constraint_name} ON {model._meta.db_table}")
else:
cursor.execute(f'DROP INDEX "{constraint_name}"')

def reverse_remove_index(self, app, schema_editor):
pass

0 comments on commit 8cdb30c

Please sign in to comment.