From 5c043286e2fde48a6230cbd2d91d5bdd3c49a418 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 5 Jan 2024 16:50:48 +0100 Subject: [PATCH] Simplified dropping spatial indexes on MySQL and Oracle. --- django/contrib/gis/db/backends/mysql/schema.py | 8 ++------ django/contrib/gis/db/backends/oracle/schema.py | 11 ++--------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/django/contrib/gis/db/backends/mysql/schema.py b/django/contrib/gis/db/backends/mysql/schema.py index 1c9fe0e565..27f6df174a 100644 --- a/django/contrib/gis/db/backends/mysql/schema.py +++ b/django/contrib/gis/db/backends/mysql/schema.py @@ -9,7 +9,6 @@ logger = logging.getLogger("django.contrib.gis") class MySQLGISSchemaEditor(DatabaseSchemaEditor): sql_add_spatial_index = "CREATE SPATIAL INDEX %(index)s ON %(table)s(%(column)s)" - sql_drop_spatial_index = "DROP INDEX %(index)s ON %(table)s" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -56,11 +55,8 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor): def remove_field(self, model, field): if isinstance(field, GeometryField) and field.spatial_index: - qn = self.connection.ops.quote_name - sql = self.sql_drop_spatial_index % { - "index": qn(self._create_spatial_index_name(model, field)), - "table": qn(model._meta.db_table), - } + index_name = self._create_spatial_index_name(model, field) + sql = self._delete_index_sql(model, index_name) try: self.execute(sql) except OperationalError: diff --git a/django/contrib/gis/db/backends/oracle/schema.py b/django/contrib/gis/db/backends/oracle/schema.py index c9192d03fa..fd542531eb 100644 --- a/django/contrib/gis/db/backends/oracle/schema.py +++ b/django/contrib/gis/db/backends/oracle/schema.py @@ -20,7 +20,6 @@ class OracleGISSchemaEditor(DatabaseSchemaEditor): "CREATE INDEX %(index)s ON %(table)s(%(column)s) " "INDEXTYPE IS MDSYS.SPATIAL_INDEX" ) - sql_drop_spatial_index = "DROP INDEX %(index)s" sql_clear_geometry_table_metadata = ( "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = %(table)s" ) @@ -98,14 +97,8 @@ class OracleGISSchemaEditor(DatabaseSchemaEditor): } ) if field.spatial_index: - self.execute( - self.sql_drop_spatial_index - % { - "index": self.quote_name( - self._create_spatial_index_name(model, field) - ), - } - ) + index_name = self._create_spatial_index_name(model, field) + self.execute(self._delete_index_sql(model, index_name)) super().remove_field(model, field) def run_geometry_sql(self):