1
0
mirror of https://github.com/django/django.git synced 2025-01-03 06:55:47 +00:00

Simplified dropping spatial indexes on MySQL and Oracle.

This commit is contained in:
Mariusz Felisiak 2024-01-05 16:50:48 +01:00 committed by GitHub
parent 45f59d0eab
commit 5c043286e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 15 deletions

View File

@ -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:

View File

@ -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):