Fixed #33607 -- Made PostgresIndex.create_sql() respect the "using" argument.
This commit is contained in:
parent
c72f6f36c1
commit
a1e4e86f92
|
@ -25,7 +25,7 @@ class PostgresIndex(Index):
|
||||||
def create_sql(self, model, schema_editor, using="", **kwargs):
|
def create_sql(self, model, schema_editor, using="", **kwargs):
|
||||||
self.check_supported(schema_editor)
|
self.check_supported(schema_editor)
|
||||||
statement = super().create_sql(
|
statement = super().create_sql(
|
||||||
model, schema_editor, using=" USING %s" % self.suffix, **kwargs
|
model, schema_editor, using=" USING %s" % (using or self.suffix), **kwargs
|
||||||
)
|
)
|
||||||
with_params = self.get_with_params()
|
with_params = self.get_with_params()
|
||||||
if with_params:
|
if with_params:
|
||||||
|
|
|
@ -8,6 +8,7 @@ from django.contrib.postgres.indexes import (
|
||||||
GistIndex,
|
GistIndex,
|
||||||
HashIndex,
|
HashIndex,
|
||||||
OpClass,
|
OpClass,
|
||||||
|
PostgresIndex,
|
||||||
SpGistIndex,
|
SpGistIndex,
|
||||||
)
|
)
|
||||||
from django.db import NotSupportedError, connection
|
from django.db import NotSupportedError, connection
|
||||||
|
@ -646,6 +647,21 @@ class SchemaTests(PostgreSQLTestCase):
|
||||||
editor.add_index(Scene, index)
|
editor.add_index(Scene, index)
|
||||||
self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
|
self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
|
||||||
|
|
||||||
|
def test_custom_suffix(self):
|
||||||
|
class CustomSuffixIndex(PostgresIndex):
|
||||||
|
suffix = "sfx"
|
||||||
|
|
||||||
|
def create_sql(self, model, schema_editor, using="gin", **kwargs):
|
||||||
|
return super().create_sql(model, schema_editor, using=using, **kwargs)
|
||||||
|
|
||||||
|
index = CustomSuffixIndex(fields=["field"], name="custom_suffix_idx")
|
||||||
|
self.assertEqual(index.suffix, "sfx")
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
self.assertIn(
|
||||||
|
" USING gin ",
|
||||||
|
str(index.create_sql(CharFieldModel, editor)),
|
||||||
|
)
|
||||||
|
|
||||||
def test_op_class(self):
|
def test_op_class(self):
|
||||||
index_name = "test_op_class"
|
index_name = "test_op_class"
|
||||||
index = Index(
|
index = Index(
|
||||||
|
|
Loading…
Reference in New Issue