Skip to content

fix: schema-qualify DROP INDEX for non-default schemas - #2289

Open
AdhamKhalifa wants to merge 1 commit into
tortoise:developfrom
AdhamKhalifa:fix/schema-qualify-drop-index
Open

AdhamKhalifa wants to merge 1 commit into
tortoise:developfrom
AdhamKhalifa:fix/schema-qualify-drop-index

Conversation

@AdhamKhalifa

Copy link
Copy Markdown

Description

Schema-qualify DROP INDEX on PostgreSQL and Oracle so RemoveIndex and partial RemoveConstraint can drop indexes that live outside the connection search_path.

remove_index() already passed a schema-qualified {table} into DROP INDEX "{name}", but the template has no {table} placeholder, so str.format() discarded it. Create still used {table_name} via _qualify_table_name(), which is why the index existed and the drop then failed with index "..." does not exist.

Name-only dialects now qualify the index identifier itself (DROP INDEX "schema"."name"). MySQL and MSSQL keep their table-scoped DROP INDEX ... ON {table} form.

Motivation and Context

Fixes #2288.

How Has This Been Tested?

  • make check
  • make test (sqlite in-memory): 1959 passed, 148 skipped, 2 xfailed
  • Added collect_sql coverage for PostgreSQL, Oracle, SQLite, MySQL, and MSSQL, including a partial unique constraint drop and the no-schema backward-compatible path

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Made with Cursor

Co-authored-by: Cursor <cursoragent@cursor.com>
@codspeed

codspeed Bot commented Sep 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing AdhamKhalifa:fix/schema-qualify-drop-index (068e783) with develop (dd964c6)

Open in CodSpeed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DROP INDEX in migrations is not schema-qualified (PostgreSQL/Oracle) — breaks RemoveIndex/RemoveConstraint for models outside the default schema

1 participant