From 8cdb30cf3b273b7a798062e408aa81f178c4e766 Mon Sep 17 00:00:00 2001 From: hirensoni913 Date: Thu, 6 Jun 2024 11:39:33 +0200 Subject: [PATCH] Added postgres support --- core/services/utils/remove_indexes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/services/utils/remove_indexes.py b/core/services/utils/remove_indexes.py index 029d4a3..6093dd1 100644 --- a/core/services/utils/remove_indexes.py +++ b/core/services/utils/remove_indexes.py @@ -1,4 +1,5 @@ from django.db import connection, migrations +import os class RemoveIndexForField(migrations.RunPython): @@ -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