1
0
mirror of https://github.com/django/django.git synced 2025-05-04 14:14:37 +00:00

Allowed indexes in contrib.postgres to have suffixes of any length.

This commit is contained in:
Nick Pope 2017-12-05 09:09:09 +00:00 committed by Tim Graham
parent 09530e61a0
commit d95f1e711b

View File

@ -1,17 +1,21 @@
from django.db.models import Index from django.db.models import Index
from django.utils.functional import cached_property
__all__ = ['BrinIndex', 'GinIndex', 'GistIndex'] __all__ = ['BrinIndex', 'GinIndex', 'GistIndex']
class MaxLengthMixin: class PostgresIndex(Index):
# 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 @cached_property
# PostgreSQL, the 30 character limit for cross-database compatibility isn't def max_name_length(self):
# applicable. # Allow an index name longer than 30 characters when the suffix is
max_name_length = 31 # 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' suffix = 'brin'
def __init__(self, *, pages_per_range=None, **kwargs): def __init__(self, *, pages_per_range=None, **kwargs):
@ -35,7 +39,7 @@ class BrinIndex(MaxLengthMixin, Index):
return statement return statement
class GinIndex(Index): class GinIndex(PostgresIndex):
suffix = 'gin' suffix = 'gin'
def __init__(self, *, fastupdate=None, gin_pending_list_limit=None, **kwargs): def __init__(self, *, fastupdate=None, gin_pending_list_limit=None, **kwargs):
@ -63,7 +67,7 @@ class GinIndex(Index):
return statement return statement
class GistIndex(MaxLengthMixin, Index): class GistIndex(PostgresIndex):
suffix = 'gist' suffix = 'gist'
def __init__(self, *, buffering=None, fillfactor=None, **kwargs): def __init__(self, *, buffering=None, fillfactor=None, **kwargs):