Refs #27869 -- Added PostgreSQL version check for GinIndex support.

This commit is contained in:
Nick Pope 2017-12-05 09:19:52 +00:00 committed by Tim Graham
parent ff9543b351
commit 743d28f553
2 changed files with 14 additions and 0 deletions

View File

@ -105,6 +105,10 @@ class GinIndex(PostgresIndex):
kwargs['gin_pending_list_limit'] = self.gin_pending_list_limit
return path, args, kwargs
def check_supported(self, schema_editor):
if self.gin_pending_list_limit and not schema_editor.connection.features.has_gin_pending_list_limit:
raise NotSupportedError('GIN option gin_pending_list_limit requires PostgreSQL 9.5+.')
def get_with_params(self):
with_params = []
if self.gin_pending_list_limit is not None:

View File

@ -185,6 +185,16 @@ class SchemaTests(PostgreSQLTestCase):
editor.remove_index(IntegerArrayModel, index)
self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table))
def test_gin_parameters_exception(self):
index_name = 'gin_options_exception'
index = GinIndex(fields=['field'], name=index_name, gin_pending_list_limit=64)
msg = 'GIN option gin_pending_list_limit requires PostgreSQL 9.5+.'
with self.assertRaisesMessage(NotSupportedError, msg):
with mock.patch('django.db.connection.features.has_gin_pending_list_limit', False):
with connection.schema_editor() as editor:
editor.add_index(IntegerArrayModel, index)
self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table))
@skipUnlessDBFeature('has_brin_index_support')
def test_brin_index(self):
index_name = 'char_field_model_field_brin'