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
b61b6346
Kaydet (Commit)
b61b6346
authored
Agu 11, 2013
tarafından
Andrew Godwin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix weird planning issues when already fully migrated.
üst
b4c493ec
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
5 deletions
+63
-5
executor.py
django/db/migrations/executor.py
+9
-4
test_executor.py
tests/migrations/test_executor.py
+33
-1
0001_initial.py
tests/migrations/test_migrations_2/0001_initial.py
+21
-0
__init__.py
tests/migrations/test_migrations_2/__init__.py
+0
-0
No files found.
django/db/migrations/executor.py
Dosyayı görüntüle @
b61b6346
...
@@ -33,10 +33,15 @@ class MigrationExecutor(object):
...
@@ -33,10 +33,15 @@ class MigrationExecutor(object):
# If the migration is already applied, do backwards mode,
# If the migration is already applied, do backwards mode,
# otherwise do forwards mode.
# otherwise do forwards mode.
elif
target
in
applied
:
elif
target
in
applied
:
for
migration
in
self
.
loader
.
graph
.
backwards_plan
(
target
)[:
-
1
]:
backwards_plan
=
self
.
loader
.
graph
.
backwards_plan
(
target
)[:
-
1
]
if
migration
in
applied
:
# We only do this if the migration is not the most recent one
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
True
))
# in its app - that is, another migration with the same app
applied
.
remove
(
migration
)
# label is in the backwards plan
if
any
(
node
[
0
]
==
target
[
0
]
for
node
in
backwards_plan
):
for
migration
in
backwards_plan
:
if
migration
in
applied
:
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
True
))
applied
.
remove
(
migration
)
else
:
else
:
for
migration
in
self
.
loader
.
graph
.
forwards_plan
(
target
):
for
migration
in
self
.
loader
.
graph
.
forwards_plan
(
target
):
if
migration
not
in
applied
:
if
migration
not
in
applied
:
...
...
tests/migrations/test_executor.py
Dosyayı görüntüle @
b61b6346
...
@@ -12,7 +12,7 @@ class ExecutorTests(TransactionTestCase):
...
@@ -12,7 +12,7 @@ class ExecutorTests(TransactionTestCase):
test failures first, as they may be propagating into here.
test failures first, as they may be propagating into here.
"""
"""
available_apps
=
[
"migrations"
]
available_apps
=
[
"migrations"
,
"django.contrib.sessions"
]
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations"
})
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations"
})
def
test_run
(
self
):
def
test_run
(
self
):
...
@@ -38,3 +38,35 @@ class ExecutorTests(TransactionTestCase):
...
@@ -38,3 +38,35 @@ class ExecutorTests(TransactionTestCase):
# Are the tables there now?
# Are the tables there now?
self
.
assertIn
(
"migrations_author"
,
connection
.
introspection
.
get_table_list
(
connection
.
cursor
()))
self
.
assertIn
(
"migrations_author"
,
connection
.
introspection
.
get_table_list
(
connection
.
cursor
()))
self
.
assertIn
(
"migrations_book"
,
connection
.
introspection
.
get_table_list
(
connection
.
cursor
()))
self
.
assertIn
(
"migrations_book"
,
connection
.
introspection
.
get_table_list
(
connection
.
cursor
()))
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations"
,
"sessions"
:
"migrations.test_migrations_2"
})
def
test_empty_plan
(
self
):
"""
Tests that re-planning a full migration of a fully-migrated set doesn't
perform spurious unmigrations and remigrations.
There was previously a bug where the executor just always performed the
backwards plan for applied migrations - which even for the most recent
migration in an app, might include other, dependent apps, and these
were being unmigrated.
"""
# Make the initial plan, check it
# We use 'sessions' here as the second app as it's always present
# in INSTALLED_APPS, so we can happily assign it test migrations.
executor
=
MigrationExecutor
(
connection
)
plan
=
executor
.
migration_plan
([(
"migrations"
,
"0002_second"
),
(
"sessions"
,
"0001_initial"
)])
self
.
assertEqual
(
plan
,
[
(
executor
.
loader
.
graph
.
nodes
[
"migrations"
,
"0001_initial"
],
False
),
(
executor
.
loader
.
graph
.
nodes
[
"migrations"
,
"0002_second"
],
False
),
(
executor
.
loader
.
graph
.
nodes
[
"sessions"
,
"0001_initial"
],
False
),
],
)
# Fake-apply all migrations
executor
.
migrate
([(
"migrations"
,
"0002_second"
),
(
"sessions"
,
"0001_initial"
)],
fake
=
True
)
# Now plan a second time and make sure it's empty
plan
=
executor
.
migration_plan
([(
"migrations"
,
"0002_second"
),
(
"sessions"
,
"0001_initial"
)])
self
.
assertEqual
(
plan
,
[])
# Erase all the fake records
executor
.
recorder
.
flush
()
tests/migrations/test_migrations_2/0001_initial.py
0 → 100644
Dosyayı görüntüle @
b61b6346
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[(
"migrations"
,
"0002_second"
)]
operations
=
[
migrations
.
CreateModel
(
"OtherAuthor"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
255
)),
(
"slug"
,
models
.
SlugField
(
null
=
True
)),
(
"age"
,
models
.
IntegerField
(
default
=
0
)),
(
"silly_field"
,
models
.
BooleanField
(
default
=
False
)),
],
),
]
tests/migrations/test_migrations_2/__init__.py
0 → 100644
Dosyayı görüntüle @
b61b6346
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