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
fc3ac657
Kaydet (Commit)
fc3ac657
authored
Tem 07, 2016
tarafından
Akshesh
Kaydeden (comit)
Tim Graham
Tem 07, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #26709 -- Checked allow_migrate_model() in Add/RemoveIndex operations.
üst
3551fb53
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
+30
-8
models.py
django/db/migrations/operations/models.py
+12
-8
test_operations.py
tests/migrations/test_operations.py
+18
-0
No files found.
django/db/migrations/operations/models.py
Dosyayı görüntüle @
fc3ac657
...
...
@@ -772,11 +772,13 @@ class AddIndex(IndexOperation):
def
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
model
=
to_state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
schema_editor
.
add_index
(
model
,
self
.
index
)
if
self
.
allow_migrate_model
(
schema_editor
.
connection
.
alias
,
model
):
schema_editor
.
add_index
(
model
,
self
.
index
)
def
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
model
=
from_state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
schema_editor
.
remove_index
(
model
,
self
.
index
)
if
self
.
allow_migrate_model
(
schema_editor
.
connection
.
alias
,
model
):
schema_editor
.
remove_index
(
model
,
self
.
index
)
def
deconstruct
(
self
):
kwargs
=
{
...
...
@@ -812,15 +814,17 @@ class RemoveIndex(IndexOperation):
def
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
model
=
from_state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
from_model_state
=
from_state
.
models
[
app_label
,
self
.
model_name_lower
]
index
=
from_model_state
.
get_index_by_name
(
self
.
name
)
schema_editor
.
remove_index
(
model
,
index
)
if
self
.
allow_migrate_model
(
schema_editor
.
connection
.
alias
,
model
):
from_model_state
=
from_state
.
models
[
app_label
,
self
.
model_name_lower
]
index
=
from_model_state
.
get_index_by_name
(
self
.
name
)
schema_editor
.
remove_index
(
model
,
index
)
def
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
model
=
to_state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
to_model_state
=
to_state
.
models
[
app_label
,
self
.
model_name_lower
]
index
=
to_model_state
.
get_index_by_name
(
self
.
name
)
schema_editor
.
add_index
(
model
,
index
)
if
self
.
allow_migrate_model
(
schema_editor
.
connection
.
alias
,
model
):
to_model_state
=
to_state
.
models
[
app_label
,
self
.
model_name_lower
]
index
=
to_model_state
.
get_index_by_name
(
self
.
name
)
schema_editor
.
add_index
(
model
,
index
)
def
deconstruct
(
self
):
kwargs
=
{
...
...
tests/migrations/test_operations.py
Dosyayı görüntüle @
fc3ac657
...
...
@@ -2347,3 +2347,21 @@ class SwappableOperationTests(OperationTestBase):
with
connection
.
schema_editor
()
as
editor
:
operation
.
database_backwards
(
"test_adfligsw"
,
editor
,
new_state
,
project_state
)
self
.
assertTableNotExists
(
"test_adfligsw_pony"
)
@override_settings
(
TEST_SWAP_MODEL
=
'migrations.SomeFakeModel'
)
def
test_indexes_ignore_swapped
(
self
):
"""
Add/RemoveIndex operations ignore swapped models.
"""
operation
=
migrations
.
AddIndex
(
'Pony'
,
models
.
Index
(
fields
=
[
'pink'
],
name
=
'my_name_idx'
))
project_state
,
new_state
=
self
.
make_test_state
(
'test_adinigsw'
,
operation
)
with
connection
.
schema_editor
()
as
editor
:
# No database queries should be run for swapped models
operation
.
database_forwards
(
'test_adinigsw'
,
editor
,
project_state
,
new_state
)
operation
.
database_backwards
(
'test_adinigsw'
,
editor
,
new_state
,
project_state
)
operation
=
migrations
.
RemoveIndex
(
'Pony'
,
models
.
Index
(
fields
=
[
'pink'
],
name
=
'my_name_idx'
))
project_state
,
new_state
=
self
.
make_test_state
(
"test_rminigsw"
,
operation
)
with
connection
.
schema_editor
()
as
editor
:
operation
.
database_forwards
(
'test_rminigsw'
,
editor
,
project_state
,
new_state
)
operation
.
database_backwards
(
'test_rminigsw'
,
editor
,
new_state
,
project_state
)
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