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
05e14e8e
Kaydet (Commit)
05e14e8e
authored
Eyl 06, 2013
tarafından
Andrew Godwin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Migration autodetector now corerctly deals with proxy models
üst
a962286b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
3 deletions
+42
-3
autodetector.py
django/db/migrations/autodetector.py
+15
-3
test_autodetector.py
tests/migrations/test_autodetector.py
+27
-0
No files found.
django/db/migrations/autodetector.py
Dosyayı görüntüle @
05e14e8e
...
...
@@ -50,8 +50,20 @@ class MigrationAutodetector(object):
self
.
migrations
=
{}
old_app_cache
=
self
.
from_state
.
render
()
new_app_cache
=
self
.
to_state
.
render
()
# Prepare lists of old/new model keys that we care about
# (i.e. ignoring proxy ones)
old_model_keys
=
[
(
al
,
mn
)
for
al
,
mn
in
self
.
from_state
.
models
.
keys
()
if
not
old_app_cache
.
get_model
(
al
,
mn
)
.
_meta
.
proxy
]
new_model_keys
=
[
(
al
,
mn
)
for
al
,
mn
in
self
.
to_state
.
models
.
keys
()
if
not
new_app_cache
.
get_model
(
al
,
mn
)
.
_meta
.
proxy
]
# Adding models. Phase 1 is adding models with no outward relationships.
added_models
=
set
(
self
.
to_state
.
models
.
keys
())
-
set
(
self
.
from_state
.
models
.
keys
()
)
added_models
=
set
(
new_model_keys
)
-
set
(
old_model_keys
)
pending_add
=
{}
for
app_label
,
model_name
in
added_models
:
model_state
=
self
.
to_state
.
models
[
app_label
,
model_name
]
...
...
@@ -130,7 +142,7 @@ class MigrationAutodetector(object):
)
self
.
add_dependency
(
app_label
,
other_app_label
)
# Removing models
removed_models
=
set
(
self
.
from_state
.
models
.
keys
())
-
set
(
self
.
to_state
.
models
.
keys
()
)
removed_models
=
set
(
old_model_keys
)
-
set
(
new_model_keys
)
for
app_label
,
model_name
in
removed_models
:
model_state
=
self
.
from_state
.
models
[
app_label
,
model_name
]
self
.
add_to_migration
(
...
...
@@ -140,7 +152,7 @@ class MigrationAutodetector(object):
)
)
# Changes within models
kept_models
=
set
(
self
.
from_state
.
models
.
keys
())
.
intersection
(
self
.
to_state
.
models
.
keys
()
)
kept_models
=
set
(
old_model_keys
)
.
intersection
(
new_model_keys
)
for
app_label
,
model_name
in
kept_models
:
old_model_state
=
self
.
from_state
.
models
[
app_label
,
model_name
]
new_model_state
=
self
.
to_state
.
models
[
app_label
,
model_name
]
...
...
tests/migrations/test_autodetector.py
Dosyayı görüntüle @
05e14e8e
...
...
@@ -16,6 +16,8 @@ class AutodetectorTests(TestCase):
author_name_longer
=
ModelState
(
"testapp"
,
"Author"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
400
))])
author_name_renamed
=
ModelState
(
"testapp"
,
"Author"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"names"
,
models
.
CharField
(
max_length
=
200
))])
author_with_book
=
ModelState
(
"testapp"
,
"Author"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
200
)),
(
"book"
,
models
.
ForeignKey
(
"otherapp.Book"
))])
author_proxy
=
ModelState
(
"testapp"
,
"AuthorProxy"
,
[],
{
"proxy"
:
True
},
(
"testapp.author"
,
))
author_proxy_notproxy
=
ModelState
(
"testapp"
,
"AuthorProxy"
,
[],
{},
(
"testapp.author"
,
))
other_pony
=
ModelState
(
"otherapp"
,
"Pony"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
))])
other_stable
=
ModelState
(
"otherapp"
,
"Stable"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
))])
third_thing
=
ModelState
(
"thirdapp"
,
"Thing"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
))])
...
...
@@ -272,3 +274,28 @@ class AutodetectorTests(TestCase):
self
.
assertEqual
(
action
.
__class__
.
__name__
,
"AlterUniqueTogether"
)
self
.
assertEqual
(
action
.
name
,
"book"
)
self
.
assertEqual
(
action
.
unique_together
,
set
([(
"title"
,
"author"
)]))
def
test_proxy_ignorance
(
self
):
"Tests that the autodetector correctly ignores proxy models"
# First, we test adding a proxy model
before
=
self
.
make_project_state
([
self
.
author_empty
])
after
=
self
.
make_project_state
([
self
.
author_empty
,
self
.
author_proxy
])
autodetector
=
MigrationAutodetector
(
before
,
after
)
changes
=
autodetector
.
_detect_changes
()
# Right number of migrations?
self
.
assertEqual
(
len
(
changes
),
0
)
# Now, we test turning a proxy model into a non-proxy model
before
=
self
.
make_project_state
([
self
.
author_empty
,
self
.
author_proxy
])
after
=
self
.
make_project_state
([
self
.
author_empty
,
self
.
author_proxy_notproxy
])
autodetector
=
MigrationAutodetector
(
before
,
after
)
changes
=
autodetector
.
_detect_changes
()
# Right number of migrations?
self
.
assertEqual
(
len
(
changes
[
'testapp'
]),
1
)
# Right number of actions?
migration
=
changes
[
'testapp'
][
0
]
self
.
assertEqual
(
len
(
migration
.
operations
),
1
)
# Right action?
action
=
migration
.
operations
[
0
]
self
.
assertEqual
(
action
.
__class__
.
__name__
,
"CreateModel"
)
self
.
assertEqual
(
action
.
name
,
"AuthorProxy"
)
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