Fixed #30903 -- Fixed migrations crash on PostgreSQL when adding Index with opclasses and ordering.

This commit is contained in:
Hannes Ljungberg 2019-10-23 22:16:55 +02:00 committed by Mariusz Felisiak
parent 2a54ce72f9
commit fa5f3291e7
4 changed files with 38 additions and 5 deletions

View file

@ -196,6 +196,33 @@ class SchemaIndexesPostgreSQLTests(TransactionTestCase):
cursor.execute(self.get_opclass_query % indexname)
self.assertCountEqual(cursor.fetchall(), [('text_pattern_ops', indexname)])
def test_ops_class_descending(self):
indexname = 'test_ops_class_ordered'
index = Index(
name=indexname,
fields=['-body'],
opclasses=['text_pattern_ops'],
)
with connection.schema_editor() as editor:
editor.add_index(IndexedArticle2, index)
with editor.connection.cursor() as cursor:
cursor.execute(self.get_opclass_query % indexname)
self.assertCountEqual(cursor.fetchall(), [('text_pattern_ops', indexname)])
def test_ops_class_descending_partial(self):
indexname = 'test_ops_class_ordered_partial'
index = Index(
name=indexname,
fields=['-body'],
opclasses=['text_pattern_ops'],
condition=Q(headline__contains='China'),
)
with connection.schema_editor() as editor:
editor.add_index(IndexedArticle2, index)
with editor.connection.cursor() as cursor:
cursor.execute(self.get_opclass_query % indexname)
self.assertCountEqual(cursor.fetchall(), [('text_pattern_ops', indexname)])
@skipUnless(connection.vendor == 'mysql', 'MySQL tests')
class SchemaIndexesMySQLTests(TransactionTestCase):