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
371ddade
Kaydet (Commit)
371ddade
authored
Mar 08, 2019
tarafından
Tim Schilling
Kaydeden (comit)
Tim Graham
Mar 08, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #30186 -- Changed MigrationRecorder.applied_migrations() to return a dict.
üst
acc04198
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
20 deletions
+37
-20
executor.py
django/db/migrations/executor.py
+5
-5
loader.py
django/db/migrations/loader.py
+3
-3
recorder.py
django/db/migrations/recorder.py
+6
-3
test_executor.py
tests/migrations/test_executor.py
+17
-3
test_loader.py
tests/migrations/test_loader.py
+6
-6
No files found.
django/db/migrations/executor.py
Dosyayı görüntüle @
371ddade
...
@@ -25,9 +25,9 @@ class MigrationExecutor:
...
@@ -25,9 +25,9 @@ class MigrationExecutor:
"""
"""
plan
=
[]
plan
=
[]
if
clean_start
:
if
clean_start
:
applied
=
set
()
applied
=
{}
else
:
else
:
applied
=
se
t
(
self
.
loader
.
applied_migrations
)
applied
=
dic
t
(
self
.
loader
.
applied_migrations
)
for
target
in
targets
:
for
target
in
targets
:
# If the target is (app_label, None), that means unmigrate everything
# If the target is (app_label, None), that means unmigrate everything
if
target
[
1
]
is
None
:
if
target
[
1
]
is
None
:
...
@@ -36,7 +36,7 @@ class MigrationExecutor:
...
@@ -36,7 +36,7 @@ class MigrationExecutor:
for
migration
in
self
.
loader
.
graph
.
backwards_plan
(
root
):
for
migration
in
self
.
loader
.
graph
.
backwards_plan
(
root
):
if
migration
in
applied
:
if
migration
in
applied
:
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
True
))
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
True
))
applied
.
remove
(
migration
)
applied
.
pop
(
migration
)
# 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
:
...
@@ -53,12 +53,12 @@ class MigrationExecutor:
...
@@ -53,12 +53,12 @@ class MigrationExecutor:
for
migration
in
self
.
loader
.
graph
.
backwards_plan
(
node
):
for
migration
in
self
.
loader
.
graph
.
backwards_plan
(
node
):
if
migration
in
applied
:
if
migration
in
applied
:
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
True
))
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
True
))
applied
.
remove
(
migration
)
applied
.
pop
(
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
:
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
False
))
plan
.
append
((
self
.
loader
.
graph
.
nodes
[
migration
],
False
))
applied
.
add
(
migration
)
applied
[
migration
]
=
self
.
loader
.
graph
.
nodes
[
migration
]
return
plan
return
plan
def
_create_project_state
(
self
,
with_applied_migrations
=
False
):
def
_create_project_state
(
self
,
with_applied_migrations
=
False
):
...
...
django/db/migrations/loader.py
Dosyayı görüntüle @
371ddade
...
@@ -206,7 +206,7 @@ class MigrationLoader:
...
@@ -206,7 +206,7 @@ class MigrationLoader:
self
.
load_disk
()
self
.
load_disk
()
# Load database data
# Load database data
if
self
.
connection
is
None
:
if
self
.
connection
is
None
:
self
.
applied_migrations
=
set
()
self
.
applied_migrations
=
{}
else
:
else
:
recorder
=
MigrationRecorder
(
self
.
connection
)
recorder
=
MigrationRecorder
(
self
.
connection
)
self
.
applied_migrations
=
recorder
.
applied_migrations
()
self
.
applied_migrations
=
recorder
.
applied_migrations
()
...
@@ -232,9 +232,9 @@ class MigrationLoader:
...
@@ -232,9 +232,9 @@ class MigrationLoader:
# Ensure the replacing migration is only marked as applied if all of
# Ensure the replacing migration is only marked as applied if all of
# its replacement targets are.
# its replacement targets are.
if
all
(
applied_statuses
):
if
all
(
applied_statuses
):
self
.
applied_migrations
.
add
(
key
)
self
.
applied_migrations
[
key
]
=
migration
else
:
else
:
self
.
applied_migrations
.
discard
(
key
)
self
.
applied_migrations
.
pop
(
key
,
None
)
# A replacing migration can be used if either all or none of its
# A replacing migration can be used if either all or none of its
# replacement targets have been applied.
# replacement targets have been applied.
if
all
(
applied_statuses
)
or
(
not
any
(
applied_statuses
)):
if
all
(
applied_statuses
)
or
(
not
any
(
applied_statuses
)):
...
...
django/db/migrations/recorder.py
Dosyayı görüntüle @
371ddade
...
@@ -69,13 +69,16 @@ class MigrationRecorder:
...
@@ -69,13 +69,16 @@ class MigrationRecorder:
raise
MigrationSchemaMissing
(
"Unable to create the django_migrations table (
%
s)"
%
exc
)
raise
MigrationSchemaMissing
(
"Unable to create the django_migrations table (
%
s)"
%
exc
)
def
applied_migrations
(
self
):
def
applied_migrations
(
self
):
"""Return a set of (app, name) of applied migrations."""
"""
Return a dict mapping (app_name, migration_name) to Migration instances
for all applied migrations.
"""
if
self
.
has_table
():
if
self
.
has_table
():
return
{
tuple
(
x
)
for
x
in
self
.
migration_qs
.
values_list
(
'app'
,
'name'
)
}
return
{
(
migration
.
app
,
migration
.
name
):
migration
for
migration
in
self
.
migration_qs
}
else
:
else
:
# If the django_migrations table doesn't exist, then no migrations
# If the django_migrations table doesn't exist, then no migrations
# are applied.
# are applied.
return
set
()
return
{}
def
record_applied
(
self
,
app
,
name
):
def
record_applied
(
self
,
app
,
name
):
"""Record that a migration was applied."""
"""Record that a migration was applied."""
...
...
tests/migrations/test_executor.py
Dosyayı görüntüle @
371ddade
...
@@ -711,7 +711,11 @@ class ExecutorUnitTests(SimpleTestCase):
...
@@ -711,7 +711,11 @@ class ExecutorUnitTests(SimpleTestCase):
graph
.
add_dependency
(
None
,
a2
,
a1
)
graph
.
add_dependency
(
None
,
a2
,
a1
)
executor
=
MigrationExecutor
(
None
)
executor
=
MigrationExecutor
(
None
)
executor
.
loader
=
FakeLoader
(
graph
,
{
a1
,
b1
,
a2
})
executor
.
loader
=
FakeLoader
(
graph
,
{
a1
:
a1_impl
,
b1
:
b1_impl
,
a2
:
a2_impl
,
})
plan
=
executor
.
migration_plan
({
a1
})
plan
=
executor
.
migration_plan
({
a1
})
...
@@ -754,7 +758,14 @@ class ExecutorUnitTests(SimpleTestCase):
...
@@ -754,7 +758,14 @@ class ExecutorUnitTests(SimpleTestCase):
graph
.
add_dependency
(
None
,
b2
,
a2
)
graph
.
add_dependency
(
None
,
b2
,
a2
)
executor
=
MigrationExecutor
(
None
)
executor
=
MigrationExecutor
(
None
)
executor
.
loader
=
FakeLoader
(
graph
,
{
a1
,
b1
,
a2
,
b2
,
a3
,
a4
})
executor
.
loader
=
FakeLoader
(
graph
,
{
a1
:
a1_impl
,
b1
:
b1_impl
,
a2
:
a2_impl
,
b2
:
b2_impl
,
a3
:
a3_impl
,
a4
:
a4_impl
,
})
plan
=
executor
.
migration_plan
({
a1
})
plan
=
executor
.
migration_plan
({
a1
})
...
@@ -791,7 +802,10 @@ class ExecutorUnitTests(SimpleTestCase):
...
@@ -791,7 +802,10 @@ class ExecutorUnitTests(SimpleTestCase):
graph
.
add_dependency
(
None
,
c1
,
a1
)
graph
.
add_dependency
(
None
,
c1
,
a1
)
executor
=
MigrationExecutor
(
None
)
executor
=
MigrationExecutor
(
None
)
executor
.
loader
=
FakeLoader
(
graph
,
{
a1
,
b1
})
executor
.
loader
=
FakeLoader
(
graph
,
{
a1
:
a1_impl
,
b1
:
b1_impl
,
})
plan
=
executor
.
migration_plan
({
a1
})
plan
=
executor
.
migration_plan
({
a1
})
...
...
tests/migrations/test_loader.py
Dosyayı görüntüle @
371ddade
...
@@ -265,7 +265,7 @@ class LoaderTests(TestCase):
...
@@ -265,7 +265,7 @@ class LoaderTests(TestCase):
def
num_nodes
():
def
num_nodes
():
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'migrations'
,
'7_auto'
)))
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'migrations'
,
'7_auto'
)))
return
len
(
plan
-
loader
.
applied_migrations
)
return
len
(
plan
-
loader
.
applied_migrations
.
keys
()
)
# Empty database: use squashed migration
# Empty database: use squashed migration
loader
.
build_graph
()
loader
.
build_graph
()
...
@@ -339,7 +339,7 @@ class LoaderTests(TestCase):
...
@@ -339,7 +339,7 @@ class LoaderTests(TestCase):
loader
.
build_graph
()
loader
.
build_graph
()
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
plan
-
loader
.
applied_migrations
plan
=
plan
-
loader
.
applied_migrations
.
keys
()
expected_plan
=
{
expected_plan
=
{
(
'app2'
,
'1_squashed_2'
),
(
'app2'
,
'1_squashed_2'
),
(
'app1'
,
'3_auto'
),
(
'app1'
,
'3_auto'
),
...
@@ -358,7 +358,7 @@ class LoaderTests(TestCase):
...
@@ -358,7 +358,7 @@ class LoaderTests(TestCase):
def
num_nodes
():
def
num_nodes
():
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'migrations'
,
'7_auto'
)))
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'migrations'
,
'7_auto'
)))
return
len
(
plan
-
loader
.
applied_migrations
)
return
len
(
plan
-
loader
.
applied_migrations
.
keys
()
)
# Empty database: use squashed migration
# Empty database: use squashed migration
loader
.
build_graph
()
loader
.
build_graph
()
...
@@ -466,7 +466,7 @@ class LoaderTests(TestCase):
...
@@ -466,7 +466,7 @@ class LoaderTests(TestCase):
# Load with nothing applied: both migrations squashed.
# Load with nothing applied: both migrations squashed.
loader
.
build_graph
()
loader
.
build_graph
()
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
plan
-
loader
.
applied_migrations
plan
=
plan
-
loader
.
applied_migrations
.
keys
()
expected_plan
=
{
expected_plan
=
{
(
'app1'
,
'1_auto'
),
(
'app1'
,
'1_auto'
),
(
'app2'
,
'1_squashed_2'
),
(
'app2'
,
'1_squashed_2'
),
...
@@ -480,7 +480,7 @@ class LoaderTests(TestCase):
...
@@ -480,7 +480,7 @@ class LoaderTests(TestCase):
recorder
.
record_applied
(
'app1'
,
'2_auto'
)
recorder
.
record_applied
(
'app1'
,
'2_auto'
)
loader
.
build_graph
()
loader
.
build_graph
()
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
plan
-
loader
.
applied_migrations
plan
=
plan
-
loader
.
applied_migrations
.
keys
()
expected_plan
=
{
expected_plan
=
{
(
'app2'
,
'1_squashed_2'
),
(
'app2'
,
'1_squashed_2'
),
(
'app1'
,
'3_auto'
),
(
'app1'
,
'3_auto'
),
...
@@ -492,7 +492,7 @@ class LoaderTests(TestCase):
...
@@ -492,7 +492,7 @@ class LoaderTests(TestCase):
recorder
.
record_applied
(
'app2'
,
'1_auto'
)
recorder
.
record_applied
(
'app2'
,
'1_auto'
)
loader
.
build_graph
()
loader
.
build_graph
()
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
set
(
loader
.
graph
.
forwards_plan
((
'app1'
,
'4_auto'
)))
plan
=
plan
-
loader
.
applied_migrations
plan
=
plan
-
loader
.
applied_migrations
.
keys
()
expected_plan
=
{
expected_plan
=
{
(
'app2'
,
'2_auto'
),
(
'app2'
,
'2_auto'
),
(
'app1'
,
'3_auto'
),
(
'app1'
,
'3_auto'
),
...
...
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