summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2017-12-05 09:09:09 +0000
committerTim Graham <timograham@gmail.com>2018-01-09 13:33:53 -0500
commitd95f1e711b9d1b3e60f7728e9710b8f542cec385 (patch)
tree2652166b16df8c146c2f7282bd26697e13a2be60
parent09530e61a0035192ca8bcdebc5ead13d14c16eb0 (diff)
Allowed indexes in contrib.postgres to have suffixes of any length.
-rw-r--r--django/contrib/postgres/indexes.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/django/contrib/postgres/indexes.py b/django/contrib/postgres/indexes.py
index 4156a7ded0..23bafb31cb 100644
--- a/django/contrib/postgres/indexes.py
+++ b/django/contrib/postgres/indexes.py
@@ -1,17 +1,21 @@
from django.db.models import Index
+from django.utils.functional import cached_property
__all__ = ['BrinIndex', 'GinIndex', 'GistIndex']
-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 PostgresIndex(Index):
+ @cached_property
+ def max_name_length(self):
+ # Allow an index name longer than 30 characters when the suffix is
+ # longer than the usual 3 character limit. The 30 character limit for
+ # cross-database compatibility isn't applicable to PostgreSQL-specific
+ # indexes.
+ return Index.max_name_length - len(Index.suffix) + len(self.suffix)
-class BrinIndex(MaxLengthMixin, Index):
+
+class BrinIndex(PostgresIndex):
suffix = 'brin'
def __init__(self, *, pages_per_range=None, **kwargs):
@@ -35,7 +39,7 @@ class BrinIndex(MaxLengthMixin, Index):
return statement
-class GinIndex(Index):
+class GinIndex(PostgresIndex):
suffix = 'gin'
def __init__(self, *, fastupdate=None, gin_pending_list_limit=None, **kwargs):
@@ -63,7 +67,7 @@ class GinIndex(Index):
return statement
-class GistIndex(MaxLengthMixin, Index):
+class GistIndex(PostgresIndex):
suffix = 'gist'
def __init__(self, *, buffering=None, fillfactor=None, **kwargs):