summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2018-09-13 09:34:02 +0200
committerTim Graham <timograham@gmail.com>2018-10-29 19:34:54 -0400
commita906c9898284a9aecb5f48bdc534e9c1273864a6 (patch)
tree3861d861073753fd0f10cf1d46413f693e43bb7d /tests/postgres_tests
parent9625d13f7b76ed22c8d4c24d411531abe8502854 (diff)
Fixed #29547 -- Added support for partial indexes.
Thanks to Ian Foote, Mariusz Felisiak, Simon Charettes, and Markus Holtermann for comments and feedback.
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/test_indexes.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py
index b9820aa362..96ab423da7 100644
--- a/tests/postgres_tests/test_indexes.py
+++ b/tests/postgres_tests/test_indexes.py
@@ -4,8 +4,12 @@ from django.contrib.postgres.indexes import (
BrinIndex, BTreeIndex, GinIndex, GistIndex, HashIndex, SpGistIndex,
)
from django.db import connection
+from django.db.models import CharField
+from django.db.models.functions import Length
+from django.db.models.query_utils import Q
from django.db.utils import NotSupportedError
from django.test import skipUnlessDBFeature
+from django.test.utils import register_lookup
from . import PostgreSQLTestCase
from .models import CharFieldModel, IntegerArrayModel
@@ -172,6 +176,36 @@ class SchemaTests(PostgreSQLTestCase):
editor.remove_index(IntegerArrayModel, index)
self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table))
+ def test_partial_gin_index(self):
+ with register_lookup(CharField, Length):
+ index_name = 'char_field_gin_partial_idx'
+ index = GinIndex(fields=['field'], name=index_name, condition=Q(field__length=40))
+ with connection.schema_editor() as editor:
+ editor.add_index(CharFieldModel, index)
+ constraints = self.get_constraints(CharFieldModel._meta.db_table)
+ self.assertEqual(constraints[index_name]['type'], 'gin')
+ with connection.schema_editor() as editor:
+ editor.remove_index(CharFieldModel, index)
+ self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
+
+ def test_partial_gin_index_with_tablespace(self):
+ with register_lookup(CharField, Length):
+ index_name = 'char_field_gin_partial_idx'
+ index = GinIndex(
+ fields=['field'],
+ name=index_name,
+ condition=Q(field__length=40),
+ db_tablespace='pg_default',
+ )
+ with connection.schema_editor() as editor:
+ editor.add_index(CharFieldModel, index)
+ self.assertIn('TABLESPACE "pg_default" ', str(index.create_sql(CharFieldModel, editor)))
+ constraints = self.get_constraints(CharFieldModel._meta.db_table)
+ self.assertEqual(constraints[index_name]['type'], 'gin')
+ with connection.schema_editor() as editor:
+ editor.remove_index(CharFieldModel, index)
+ self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
+
@skipUnlessDBFeature('has_gin_pending_list_limit')
def test_gin_parameters(self):
index_name = 'integer_array_gin_params'