Refs #27097, #27098 -- Moved PostgreSQL index type introspection to get_constraints().

This commit is contained in:
Akshesh 2016-08-25 12:42:17 +05:30 committed by Tim Graham
parent 3fe92f4477
commit 4c7bf83cde
4 changed files with 24 additions and 25 deletions

View file

@ -33,23 +33,24 @@ class GinIndexTests(PostgreSQLTestCase):
class SchemaTests(PostgreSQLTestCase):
def get_indexes(self, table):
def get_constraints(self, table):
"""
Get the indexes on the table using a new cursor.
"""
with connection.cursor() as cursor:
return connection.introspection.get_indexes(cursor, table)
return connection.introspection.get_constraints(cursor, table)
def test_gin_index(self):
# Ensure the table is there and doesn't have an index.
self.assertNotIn('field', self.get_indexes(IntegerArrayModel._meta.db_table))
self.assertNotIn('field', self.get_constraints(IntegerArrayModel._meta.db_table))
# Add the index
index = GinIndex(fields=['field'], name='integer_array_model_field_gin')
with connection.schema_editor() as editor:
editor.add_index(IntegerArrayModel, index)
self.assertIn('field', self.get_indexes(IntegerArrayModel._meta.db_table))
self.assertEqual(self.get_indexes(IntegerArrayModel._meta.db_table)['field']['type'], 'gin')
self.assertIn('integer_array_model_field_gin', self.get_constraints(IntegerArrayModel._meta.db_table))
constraints = self.get_constraints(IntegerArrayModel._meta.db_table)
self.assertEqual(constraints['integer_array_model_field_gin']['type'], 'gin')
# Drop the index
with connection.schema_editor() as editor:
editor.remove_index(IntegerArrayModel, index)
self.assertNotIn('field', self.get_indexes(IntegerArrayModel._meta.db_table))
self.assertNotIn('integer_array_model_field_gin', self.get_constraints(IntegerArrayModel._meta.db_table))