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
2a9c4b49
Kaydet (Commit)
2a9c4b49
authored
Eki 26, 2014
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Passed around the state between migrations
Refs #23745.
üst
285bd02c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
10 deletions
+17
-10
executor.py
django/db/migrations/executor.py
+16
-9
test_executor.py
tests/migrations/test_executor.py
+1
-1
No files found.
django/db/migrations/executor.py
Dosyayı görüntüle @
2a9c4b49
...
...
@@ -63,11 +63,14 @@ class MigrationExecutor(object):
"""
if
plan
is
None
:
plan
=
self
.
migration_plan
(
targets
)
state
=
None
for
migration
,
backwards
in
plan
:
if
state
is
None
:
state
=
self
.
loader
.
project_state
((
migration
.
app_label
,
migration
.
name
),
at_end
=
False
)
if
not
backwards
:
s
elf
.
apply_migration
(
migration
,
fake
=
fake
)
s
tate
=
self
.
apply_migration
(
state
,
migration
,
fake
=
fake
)
else
:
s
elf
.
unapply_migration
(
migration
,
fake
=
fake
)
s
tate
=
self
.
unapply_migration
(
state
,
migration
,
fake
=
fake
)
def
collect_sql
(
self
,
plan
):
"""
...
...
@@ -75,17 +78,19 @@ class MigrationExecutor(object):
statements that represent the best-efforts version of that plan.
"""
statements
=
[]
state
=
None
for
migration
,
backwards
in
plan
:
with
self
.
connection
.
schema_editor
(
collect_sql
=
True
)
as
schema_editor
:
project_state
=
self
.
loader
.
project_state
((
migration
.
app_label
,
migration
.
name
),
at_end
=
False
)
if
state
is
None
:
state
=
self
.
loader
.
project_state
((
migration
.
app_label
,
migration
.
name
),
at_end
=
False
)
if
not
backwards
:
migration
.
apply
(
project_
state
,
schema_editor
,
collect_sql
=
True
)
state
=
migration
.
apply
(
state
,
schema_editor
,
collect_sql
=
True
)
else
:
migration
.
unapply
(
project_
state
,
schema_editor
,
collect_sql
=
True
)
state
=
migration
.
unapply
(
state
,
schema_editor
,
collect_sql
=
True
)
statements
.
extend
(
schema_editor
.
collected_sql
)
return
statements
def
apply_migration
(
self
,
migration
,
fake
=
False
):
def
apply_migration
(
self
,
state
,
migration
,
fake
=
False
):
"""
Runs a migration forwards.
"""
...
...
@@ -93,7 +98,7 @@ class MigrationExecutor(object):
self
.
progress_callback
(
"apply_start"
,
migration
,
fake
)
if
not
fake
:
# Test to see if this is an already-applied initial migration
if
self
.
detect_soft_applied
(
migration
):
if
self
.
detect_soft_applied
(
state
,
migration
):
fake
=
True
else
:
# Alright, do it normally
...
...
@@ -109,8 +114,9 @@ class MigrationExecutor(object):
# Report progress
if
self
.
progress_callback
:
self
.
progress_callback
(
"apply_success"
,
migration
,
fake
)
return
state
def
unapply_migration
(
self
,
migration
,
fake
=
False
):
def
unapply_migration
(
self
,
state
,
migration
,
fake
=
False
):
"""
Runs a migration backwards.
"""
...
...
@@ -129,8 +135,9 @@ class MigrationExecutor(object):
# Report progress
if
self
.
progress_callback
:
self
.
progress_callback
(
"unapply_success"
,
migration
,
fake
)
return
state
def
detect_soft_applied
(
self
,
migration
):
def
detect_soft_applied
(
self
,
project_state
,
migration
):
"""
Tests whether a migration has been implicitly applied - that the
tables it would create exist. This is intended only for use
...
...
tests/migrations/test_executor.py
Dosyayı görüntüle @
2a9c4b49
...
...
@@ -223,7 +223,7 @@ class ExecutorTests(MigrationTestBase):
global_apps
.
get_app_config
(
"migrations"
)
.
models
[
"author"
]
=
migrations_apps
.
get_model
(
"migrations"
,
"author"
)
try
:
migration
=
executor
.
loader
.
get_migration
(
"auth"
,
"0001_initial"
)
self
.
assertEqual
(
executor
.
detect_soft_applied
(
migration
),
True
)
self
.
assertEqual
(
executor
.
detect_soft_applied
(
None
,
migration
),
True
)
finally
:
connection
.
introspection
.
table_names
=
old_table_names
del
global_apps
.
get_app_config
(
"migrations"
)
.
models
[
"author"
]
...
...
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