mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
This commit is contained in:
parent
3fe92f4477
commit
4c7bf83cde
4 changed files with 24 additions and 25 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue