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:
parent
45f59d0eab
commit
5c043286e2
@ -9,7 +9,6 @@ logger = logging.getLogger("django.contrib.gis")
|
|||||||
|
|
||||||
class MySQLGISSchemaEditor(DatabaseSchemaEditor):
|
class MySQLGISSchemaEditor(DatabaseSchemaEditor):
|
||||||
sql_add_spatial_index = "CREATE SPATIAL INDEX %(index)s ON %(table)s(%(column)s)"
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -56,11 +55,8 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor):
|
|||||||
|
|
||||||
def remove_field(self, model, field):
|
def remove_field(self, model, field):
|
||||||
if isinstance(field, GeometryField) and field.spatial_index:
|
if isinstance(field, GeometryField) and field.spatial_index:
|
||||||
qn = self.connection.ops.quote_name
|
index_name = self._create_spatial_index_name(model, field)
|
||||||
sql = self.sql_drop_spatial_index % {
|
sql = self._delete_index_sql(model, index_name)
|
||||||
"index": qn(self._create_spatial_index_name(model, field)),
|
|
||||||
"table": qn(model._meta.db_table),
|
|
||||||
}
|
|
||||||
try:
|
try:
|
||||||
self.execute(sql)
|
self.execute(sql)
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
|
@ -20,7 +20,6 @@ class OracleGISSchemaEditor(DatabaseSchemaEditor):
|
|||||||
"CREATE INDEX %(index)s ON %(table)s(%(column)s) "
|
"CREATE INDEX %(index)s ON %(table)s(%(column)s) "
|
||||||
"INDEXTYPE IS MDSYS.SPATIAL_INDEX"
|
"INDEXTYPE IS MDSYS.SPATIAL_INDEX"
|
||||||
)
|
)
|
||||||
sql_drop_spatial_index = "DROP INDEX %(index)s"
|
|
||||||
sql_clear_geometry_table_metadata = (
|
sql_clear_geometry_table_metadata = (
|
||||||
"DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = %(table)s"
|
"DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = %(table)s"
|
||||||
)
|
)
|
||||||
@ -98,14 +97,8 @@ class OracleGISSchemaEditor(DatabaseSchemaEditor):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if field.spatial_index:
|
if field.spatial_index:
|
||||||
self.execute(
|
index_name = self._create_spatial_index_name(model, field)
|
||||||
self.sql_drop_spatial_index
|
self.execute(self._delete_index_sql(model, index_name))
|
||||||
% {
|
|
||||||
"index": self.quote_name(
|
|
||||||
self._create_spatial_index_name(model, field)
|
|
||||||
),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
super().remove_field(model, field)
|
super().remove_field(model, field)
|
||||||
|
|
||||||
def run_geometry_sql(self):
|
def run_geometry_sql(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user