Refs #32721 -- Made PostGISSchemaEditor._create_index_sql() call super()._create_index_sql().
This commit is contained in:
parent
c6d88a1872
commit
99bc67a9e7
|
@ -1,11 +1,11 @@
|
||||||
from django.db.backends.ddl_references import Statement
|
|
||||||
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
||||||
|
from django.db.models.expressions import Col, Func
|
||||||
|
|
||||||
|
|
||||||
class PostGISSchemaEditor(DatabaseSchemaEditor):
|
class PostGISSchemaEditor(DatabaseSchemaEditor):
|
||||||
geom_index_type = 'GIST'
|
geom_index_type = 'GIST'
|
||||||
geom_index_ops_nd = 'GIST_GEOMETRY_OPS_ND'
|
geom_index_ops_nd = 'GIST_GEOMETRY_OPS_ND'
|
||||||
rast_index_wrapper = 'ST_ConvexHull(%s)'
|
rast_index_template = 'ST_ConvexHull(%(expressions)s)'
|
||||||
|
|
||||||
sql_alter_column_to_3d = "ALTER COLUMN %(column)s TYPE %(type)s USING ST_Force3D(%(column)s)::%(type)s"
|
sql_alter_column_to_3d = "ALTER COLUMN %(column)s TYPE %(type)s USING ST_Force3D(%(column)s)::%(type)s"
|
||||||
sql_alter_column_to_2d = "ALTER COLUMN %(column)s TYPE %(type)s USING ST_Force2D(%(column)s)::%(type)s"
|
sql_alter_column_to_2d = "ALTER COLUMN %(column)s TYPE %(type)s USING ST_Force2D(%(column)s)::%(type)s"
|
||||||
|
@ -23,29 +23,28 @@ class PostGISSchemaEditor(DatabaseSchemaEditor):
|
||||||
return super()._create_index_sql(model, fields=fields, **kwargs)
|
return super()._create_index_sql(model, fields=fields, **kwargs)
|
||||||
|
|
||||||
field = fields[0]
|
field = fields[0]
|
||||||
field_column = self.quote_name(field.column)
|
expressions = None
|
||||||
|
opclasses = None
|
||||||
if field.geom_type == 'RASTER':
|
if field.geom_type == 'RASTER':
|
||||||
# For raster fields, wrap index creation SQL statement with ST_ConvexHull.
|
# For raster fields, wrap index creation SQL statement with ST_ConvexHull.
|
||||||
# Indexes on raster columns are based on the convex hull of the raster.
|
# Indexes on raster columns are based on the convex hull of the raster.
|
||||||
field_column = self.rast_index_wrapper % field_column
|
expressions = Func(Col(None, field), template=self.rast_index_template)
|
||||||
|
fields = None
|
||||||
elif field.dim > 2 and not field.geography:
|
elif field.dim > 2 and not field.geography:
|
||||||
# Use "nd" ops which are fast on multidimensional cases
|
# Use "nd" ops which are fast on multidimensional cases
|
||||||
field_column = "%s %s" % (field_column, self.geom_index_ops_nd)
|
opclasses = [self.geom_index_ops_nd]
|
||||||
if kwargs.get('name') is None:
|
if not kwargs.get('name'):
|
||||||
index_name = '%s_%s_id' % (model._meta.db_table, field.column)
|
name = '%s_%s_id' % (model._meta.db_table, field.column)
|
||||||
else:
|
else:
|
||||||
index_name = kwargs['name']
|
name = kwargs['name']
|
||||||
|
|
||||||
return Statement(
|
return super()._create_index_sql(
|
||||||
self.sql_create_index,
|
model,
|
||||||
name=self.quote_name(index_name),
|
fields=fields,
|
||||||
table=self.quote_name(model._meta.db_table),
|
name=name,
|
||||||
using=' USING %s' % self.geom_index_type,
|
using=' USING %s' % self.geom_index_type,
|
||||||
columns=field_column,
|
opclasses=opclasses,
|
||||||
extra='',
|
expressions=expressions,
|
||||||
condition='',
|
|
||||||
include='',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _alter_column_type_sql(self, table, old_field, new_field, new_type):
|
def _alter_column_type_sql(self, table, old_field, new_field, new_type):
|
||||||
|
|
Loading…
Reference in New Issue