mirror of
https://github.com/django/django.git
synced 2025-06-06 20:19:13 +00:00
[1.11.x] Refs #27935 -- Fixed BrinIndex.max_name_length if a project's default database isn't PostgreSQL.
Thanks Florian Apolloner for the report. Backport of 2867b7eb4b8477710f11707d4b975db10e5f91a7 from master
This commit is contained in:
parent
0b93a992e5
commit
40b843488a
@ -1,14 +1,17 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import connection
|
|
||||||
from django.db.models import Index
|
from django.db.models import Index
|
||||||
from django.utils.functional import cached_property
|
|
||||||
|
|
||||||
__all__ = ['BrinIndex', 'GinIndex']
|
__all__ = ['BrinIndex', 'GinIndex']
|
||||||
|
|
||||||
|
|
||||||
class BrinIndex(Index):
|
class BrinIndex(Index):
|
||||||
suffix = 'brin'
|
suffix = 'brin'
|
||||||
|
# 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
|
||||||
|
|
||||||
def __init__(self, fields=[], name=None, pages_per_range=None):
|
def __init__(self, fields=[], name=None, pages_per_range=None):
|
||||||
if pages_per_range is not None and pages_per_range <= 0:
|
if pages_per_range is not None and pages_per_range <= 0:
|
||||||
@ -38,14 +41,6 @@ class BrinIndex(Index):
|
|||||||
schema_editor.quote_value(self.pages_per_range)) + parameters['extra']
|
schema_editor.quote_value(self.pages_per_range)) + parameters['extra']
|
||||||
return parameters
|
return parameters
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def max_name_length(self):
|
|
||||||
# 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.
|
|
||||||
return connection.ops.max_name_length()
|
|
||||||
|
|
||||||
|
|
||||||
class GinIndex(Index):
|
class GinIndex(Index):
|
||||||
suffix = 'gin'
|
suffix = 'gin'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user