fix(postgres): drop_index_if_exists uses DROP INDEX IF EXISTS (#35636)
* fix(postgres): drop_index_if_exists uses DROP INDEX IF EXISTS * fix(linting): apply pre-commit to code --------- Co-authored-by: Matt Howard <github.severity519@passmail.net> Co-authored-by: AarDG10 <aarol.dsouza@gmail.com>
This commit is contained in:
parent
f71035c6ba
commit
261e78e492
1 changed files with 6 additions and 1 deletions
|
|
@ -193,7 +193,12 @@ def drop_index_if_exists(table: str, index: str):
|
|||
return
|
||||
|
||||
try:
|
||||
frappe.db.sql_ddl(f"ALTER TABLE `{table}` DROP INDEX `{index}`")
|
||||
if frappe.db.db_type == "postgres":
|
||||
# Postgres drops indexes with DROP INDEX, not ALTER TABLE ... DROP INDEX
|
||||
safe_index = index.replace('"', '""')
|
||||
frappe.db.sql_ddl(f'DROP INDEX IF EXISTS "{safe_index}"')
|
||||
else:
|
||||
frappe.db.sql_ddl(f"ALTER TABLE `{table}` DROP INDEX `{index}`")
|
||||
except Exception as e:
|
||||
frappe.log_error("Failed to drop index")
|
||||
click.secho(f"x Failed to drop index {index} from {table}\n {e!s}", fg="red")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue