Fixed #32721 -- Fixed migrations crash when adding namespaced spatial indexes on PostGIS.
This commit is contained in:
parent
99bc67a9e7
commit
29345aecf6
|
@ -33,10 +33,9 @@ class PostGISSchemaEditor(DatabaseSchemaEditor):
|
||||||
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
|
||||||
opclasses = [self.geom_index_ops_nd]
|
opclasses = [self.geom_index_ops_nd]
|
||||||
if not kwargs.get('name'):
|
name = kwargs.get('name')
|
||||||
name = '%s_%s_id' % (model._meta.db_table, field.column)
|
if not name:
|
||||||
else:
|
name = self._create_index_name(model._meta.db_table, [field.column], '_id')
|
||||||
name = kwargs['name']
|
|
||||||
|
|
||||||
return super()._create_index_sql(
|
return super()._create_index_sql(
|
||||||
model,
|
model,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
from django.contrib.gis.db import models
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.models import Index
|
from django.db.models import Index
|
||||||
from django.test import TransactionTestCase
|
from django.test import TransactionTestCase
|
||||||
|
from django.test.utils import isolate_apps
|
||||||
|
|
||||||
from .models import City
|
from .models import City
|
||||||
|
|
||||||
|
@ -38,6 +40,30 @@ class SchemaIndexesTests(TransactionTestCase):
|
||||||
str(index.create_sql(City, editor)),
|
str(index.create_sql(City, editor)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@isolate_apps('gis_tests.geoapp')
|
||||||
|
def test_namespaced_db_table(self):
|
||||||
|
if not connection.ops.postgis:
|
||||||
|
self.skipTest('PostGIS-specific test.')
|
||||||
|
|
||||||
|
class SchemaCity(models.Model):
|
||||||
|
point = models.PointField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'geoapp'
|
||||||
|
db_table = 'django_schema"."geoapp_schema_city'
|
||||||
|
|
||||||
|
index = Index(fields=['point'])
|
||||||
|
editor = connection.schema_editor()
|
||||||
|
create_index_sql = str(index.create_sql(SchemaCity, editor))
|
||||||
|
self.assertIn(
|
||||||
|
'%s USING ' % editor.quote_name(SchemaCity._meta.db_table),
|
||||||
|
create_index_sql,
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
'CREATE INDEX "geoapp_schema_city_point_9ed70651_id" ',
|
||||||
|
create_index_sql,
|
||||||
|
)
|
||||||
|
|
||||||
def test_index_name(self):
|
def test_index_name(self):
|
||||||
if not self.has_spatial_indexes(City._meta.db_table):
|
if not self.has_spatial_indexes(City._meta.db_table):
|
||||||
self.skipTest('Spatial indexes in Meta.indexes are not supported.')
|
self.skipTest('Spatial indexes in Meta.indexes are not supported.')
|
||||||
|
|
|
@ -210,7 +210,7 @@ class OperationTests(OperationTestCase):
|
||||||
self.assertSpatialIndexExists('gis_neighborhood', 'point3d')
|
self.assertSpatialIndexExists('gis_neighborhood', 'point3d')
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
index_name = 'gis_neighborhood_point3d_id'
|
index_name = 'gis_neighborhood_point3d_113bc868_id'
|
||||||
cursor.execute(self.get_opclass_query, [index_name])
|
cursor.execute(self.get_opclass_query, [index_name])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cursor.fetchall(),
|
cursor.fetchall(),
|
||||||
|
|
Loading…
Reference in New Issue