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
3f76d140
Kaydet (Commit)
3f76d140
authored
Tem 15, 2016
tarafından
Jon Dufresne
Kaydeden (comit)
Tim Graham
Tem 15, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #26889 -- Refactored SchemaEditor to allow backend specific indexes.
üst
f8bfa806
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
18 deletions
+15
-18
schema.py
django/db/backends/base/schema.py
+11
-4
schema.py
django/db/backends/postgresql/schema.py
+3
-13
tests.py
tests/indexes/tests.py
+1
-1
No files found.
django/db/backends/base/schema.py
Dosyayı görüntüle @
3f76d140
...
...
@@ -430,8 +430,7 @@ class BaseDatabaseSchemaEditor(object):
}
self
.
execute
(
sql
)
# Add an index, if required
if
field
.
db_index
and
not
field
.
unique
:
self
.
deferred_sql
.
append
(
self
.
_create_index_sql
(
model
,
[
field
]))
self
.
deferred_sql
.
extend
(
self
.
_field_indexes_sql
(
model
,
field
))
# Add any FK constraints later
if
field
.
remote_field
and
self
.
connection
.
features
.
supports_foreign_keys
and
field
.
db_constraint
:
self
.
deferred_sql
.
append
(
self
.
_create_fk_sql
(
model
,
field
,
"_fk_
%(to_table)
s_
%(to_column)
s"
))
...
...
@@ -897,14 +896,22 @@ class BaseDatabaseSchemaEditor(object):
return
[]
output
=
[]
for
field
in
model
.
_meta
.
local_fields
:
if
self
.
_field_should_be_indexed
(
model
,
field
):
output
.
append
(
self
.
_create_index_sql
(
model
,
[
field
],
suffix
=
""
))
output
.
extend
(
self
.
_field_indexes_sql
(
model
,
field
))
for
field_names
in
model
.
_meta
.
index_together
:
fields
=
[
model
.
_meta
.
get_field
(
field
)
for
field
in
field_names
]
output
.
append
(
self
.
_create_index_sql
(
model
,
fields
,
suffix
=
"_idx"
))
return
output
def
_field_indexes_sql
(
self
,
model
,
field
):
"""
Return a list of all index SQL statements for the specified field.
"""
output
=
[]
if
self
.
_field_should_be_indexed
(
model
,
field
):
output
.
append
(
self
.
_create_index_sql
(
model
,
[
field
]))
return
output
def
_field_should_be_indexed
(
self
,
model
,
field
):
return
field
.
db_index
and
not
field
.
unique
...
...
django/db/backends/postgresql/schema.py
Dosyayı görüntüle @
3f76d140
...
...
@@ -17,21 +17,11 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def
quote_value
(
self
,
value
):
return
psycopg2
.
extensions
.
adapt
(
value
)
def
add_field
(
self
,
model
,
field
):
super
(
DatabaseSchemaEditor
,
self
)
.
add_field
(
model
,
field
)
def
_field_indexes_sql
(
self
,
model
,
field
):
output
=
super
(
DatabaseSchemaEditor
,
self
)
.
_field_indexes_sql
(
model
,
field
)
like_index_statement
=
self
.
_create_like_index_sql
(
model
,
field
)
if
like_index_statement
is
not
None
:
self
.
deferred_sql
.
append
(
like_index_statement
)
def
_model_indexes_sql
(
self
,
model
):
output
=
super
(
DatabaseSchemaEditor
,
self
)
.
_model_indexes_sql
(
model
)
if
not
model
.
_meta
.
managed
or
model
.
_meta
.
proxy
or
model
.
_meta
.
swapped
:
return
output
for
field
in
model
.
_meta
.
local_fields
:
like_index_statement
=
self
.
_create_like_index_sql
(
model
,
field
)
if
like_index_statement
is
not
None
:
output
.
append
(
like_index_statement
)
output
.
append
(
like_index_statement
)
return
output
def
_create_like_index_sql
(
self
,
model
,
field
):
...
...
tests/indexes/tests.py
Dosyayı görüntüle @
3f76d140
...
...
@@ -46,7 +46,7 @@ class SchemaIndexesTests(TestCase):
from
.models
import
IndexedArticle
index_sql
=
connection
.
schema_editor
()
.
_model_indexes_sql
(
IndexedArticle
)
self
.
assertEqual
(
len
(
index_sql
),
5
)
self
.
assertIn
(
'("headline" varchar_pattern_ops)'
,
index_sql
[
2
])
self
.
assertIn
(
'("headline" varchar_pattern_ops)'
,
index_sql
[
1
])
self
.
assertIn
(
'("body" text_pattern_ops)'
,
index_sql
[
3
])
# unique=True and db_index=True should only create the varchar-specific
# index (#19441).
...
...
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