summaryrefslogtreecommitdiff
path: root/django/contrib/postgres
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/postgres')
-rw-r--r--django/contrib/postgres/indexes.py37
-rw-r--r--django/contrib/postgres/operations.py6
2 files changed, 40 insertions, 3 deletions
diff --git a/django/contrib/postgres/indexes.py b/django/contrib/postgres/indexes.py
index cbfd43c1de..4156a7ded0 100644
--- a/django/contrib/postgres/indexes.py
+++ b/django/contrib/postgres/indexes.py
@@ -1,16 +1,19 @@
from django.db.models import Index
-__all__ = ['BrinIndex', 'GinIndex']
+__all__ = ['BrinIndex', 'GinIndex', 'GistIndex']
-class BrinIndex(Index):
- suffix = 'brin'
+class MaxLengthMixin:
# Allow an index name longer than 30 characters since the suffix is 4
# characters (usual limit is 3). Since this index can only be used on
# PostgreSQL, the 30 character limit for cross-database compatibility isn't
# applicable.
max_name_length = 31
+
+class BrinIndex(MaxLengthMixin, Index):
+ suffix = 'brin'
+
def __init__(self, *, pages_per_range=None, **kwargs):
if pages_per_range is not None and pages_per_range <= 0:
raise ValueError('pages_per_range must be None or a positive integer')
@@ -58,3 +61,31 @@ class GinIndex(Index):
if with_params:
statement.parts['extra'] = 'WITH ({}) {}'.format(', '.join(with_params), statement.parts['extra'])
return statement
+
+
+class GistIndex(MaxLengthMixin, Index):
+ suffix = 'gist'
+
+ def __init__(self, *, buffering=None, fillfactor=None, **kwargs):
+ self.buffering = buffering
+ self.fillfactor = fillfactor
+ super().__init__(**kwargs)
+
+ def deconstruct(self):
+ path, args, kwargs = super().deconstruct()
+ if self.buffering is not None:
+ kwargs['buffering'] = self.buffering
+ if self.fillfactor is not None:
+ kwargs['fillfactor'] = self.fillfactor
+ return path, args, kwargs
+
+ def create_sql(self, model, schema_editor):
+ statement = super().create_sql(model, schema_editor, using=' USING gist')
+ with_params = []
+ if self.buffering is not None:
+ with_params.append('buffering = {}'.format('on' if self.buffering else 'off'))
+ if self.fillfactor is not None:
+ with_params.append('fillfactor = %s' % self.fillfactor)
+ if with_params:
+ statement.parts['extra'] = 'WITH ({}) {}'.format(', '.join(with_params), statement.parts['extra'])
+ return statement
diff --git a/django/contrib/postgres/operations.py b/django/contrib/postgres/operations.py
index cb9765928a..be9ed9cb23 100644
--- a/django/contrib/postgres/operations.py
+++ b/django/contrib/postgres/operations.py
@@ -33,6 +33,12 @@ class BtreeGinExtension(CreateExtension):
self.name = 'btree_gin'
+class BtreeGistExtension(CreateExtension):
+
+ def __init__(self):
+ self.name = 'btree_gist'
+
+
class CITextExtension(CreateExtension):
def __init__(self):