Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
ff9543b3
Kaydet (Commit)
ff9543b3
authored
Ara 05, 2017
tarafından
Nick Pope
Kaydeden (comit)
Tim Graham
Agu 02, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #25809, #28990 -- Added PostgreSQL version check for BrinIndex support.
üst
6b4d1ec8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
indexes.py
django/contrib/postgres/indexes.py
+11
-0
test_indexes.py
tests/postgres_tests/test_indexes.py
+22
-0
No files found.
django/contrib/postgres/indexes.py
Dosyayı görüntüle @
ff9543b3
from
django.db.models
import
Index
from
django.db.utils
import
NotSupportedError
from
django.utils.functional
import
cached_property
__all__
=
[
...
...
@@ -18,6 +19,7 @@ class PostgresIndex(Index):
return
Index
.
max_name_length
-
len
(
Index
.
suffix
)
+
len
(
self
.
suffix
)
def
create_sql
(
self
,
model
,
schema_editor
,
using
=
''
):
self
.
check_supported
(
schema_editor
)
statement
=
super
()
.
create_sql
(
model
,
schema_editor
,
using
=
' USING
%
s'
%
self
.
suffix
)
with_params
=
self
.
get_with_params
()
if
with_params
:
...
...
@@ -27,6 +29,9 @@ class PostgresIndex(Index):
)
return
statement
def
check_supported
(
self
,
schema_editor
):
pass
def
get_with_params
(
self
):
return
[]
...
...
@@ -49,6 +54,12 @@ class BrinIndex(PostgresIndex):
kwargs
[
'pages_per_range'
]
=
self
.
pages_per_range
return
path
,
args
,
kwargs
def
check_supported
(
self
,
schema_editor
):
if
not
schema_editor
.
connection
.
features
.
has_brin_index_support
:
raise
NotSupportedError
(
'BRIN indexes require PostgreSQL 9.5+.'
)
if
self
.
autosummarize
and
not
schema_editor
.
connection
.
features
.
has_brin_autosummarize
:
raise
NotSupportedError
(
'BRIN option autosummarize requires PostgreSQL 10+.'
)
def
get_with_params
(
self
):
with_params
=
[]
if
self
.
autosummarize
is
not
None
:
...
...
tests/postgres_tests/test_indexes.py
Dosyayı görüntüle @
ff9543b3
from
unittest
import
mock
from
django.contrib.postgres.indexes
import
(
BrinIndex
,
BTreeIndex
,
GinIndex
,
GistIndex
,
HashIndex
,
SpGistIndex
,
)
from
django.db
import
connection
from
django.db.utils
import
NotSupportedError
from
django.test
import
skipUnlessDBFeature
from
.
import
PostgreSQLTestCase
...
...
@@ -208,6 +211,25 @@ class SchemaTests(PostgreSQLTestCase):
editor
.
remove_index
(
CharFieldModel
,
index
)
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
def
test_brin_index_not_supported
(
self
):
index_name
=
'brin_index_exception'
index
=
BrinIndex
(
fields
=
[
'field'
],
name
=
index_name
)
with
self
.
assertRaisesMessage
(
NotSupportedError
,
'BRIN indexes require PostgreSQL 9.5+.'
):
with
mock
.
patch
(
'django.db.connection.features.has_brin_index_support'
,
False
):
with
connection
.
schema_editor
()
as
editor
:
editor
.
add_index
(
CharFieldModel
,
index
)
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
@skipUnlessDBFeature
(
'has_brin_index_support'
)
def
test_brin_autosummarize_not_supported
(
self
):
index_name
=
'brin_options_exception'
index
=
BrinIndex
(
fields
=
[
'field'
],
name
=
index_name
,
autosummarize
=
True
)
with
self
.
assertRaisesMessage
(
NotSupportedError
,
'BRIN option autosummarize requires PostgreSQL 10+.'
):
with
mock
.
patch
(
'django.db.connection.features.has_brin_autosummarize'
,
False
):
with
connection
.
schema_editor
()
as
editor
:
editor
.
add_index
(
CharFieldModel
,
index
)
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
def
test_btree_index
(
self
):
# Ensure the table is there and doesn't have an index.
self
.
assertNotIn
(
'field'
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment