Skip to content

Commit

Permalink
Simplified dropping spatial indexes on MySQL and Oracle.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixxm authored Jan 5, 2024
1 parent 45f59d0 commit 5c04328
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
8 changes: 2 additions & 6 deletions django/contrib/gis/db/backends/mysql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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)
Expand Down Expand Up @@ -56,11 +55,8 @@ def add_field(self, model, field):

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:
Expand Down
11 changes: 2 additions & 9 deletions django/contrib/gis/db/backends/oracle/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -98,14 +97,8 @@ def remove_field(self, model, field):
}
)
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):
Expand Down

0 comments on commit 5c04328

Please sign in to comment.