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
13d613f8
Kaydet (Commit)
13d613f8
authored
Kas 15, 2014
tarafından
Klaas van Schelven
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use topological sort for migration operation dependency resolution
rather than an ad-hoc algorithm
üst
4f90c996
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
25 deletions
+53
-25
AUTHORS
AUTHORS
+1
-0
autodetector.py
django/db/migrations/autodetector.py
+15
-22
topological_sort.py
django/db/migrations/topological_sort.py
+34
-0
test_autodetector.py
tests/migrations/test_autodetector.py
+3
-3
No files found.
AUTHORS
Dosyayı görüntüle @
13d613f8
...
...
@@ -377,6 +377,7 @@ answer newbie questions, and generally made Django that much better:
Kevin McConnell <kevin.mcconnell@gmail.com>
Kieran Holland <http://www.kieranholland.com>
kilian <kilian.cavalotti@lip6.fr>
Klaas van Schelven <klaas@vanschelven.com>
knox <christobzr@gmail.com>
konrad@gwu.edu
Kowito Charoenratchatabhan <kowito@felspar.com>
...
...
django/db/migrations/autodetector.py
Dosyayı görüntüle @
13d613f8
...
...
@@ -14,6 +14,8 @@ from django.db.migrations.questioner import MigrationQuestioner
from
django.db.migrations.optimizer
import
MigrationOptimizer
from
django.db.migrations.operations.models
import
AlterModelOptions
from
.topological_sort
import
stable_topological_sort
class
MigrationAutodetector
(
object
):
"""
...
...
@@ -191,28 +193,19 @@ class MigrationAutodetector(object):
# isn't bad, but we need to pull a few things around so FKs work nicely
# inside the same app
for
app_label
,
ops
in
sorted
(
self
.
generated_operations
.
items
()):
for
i
in
range
(
10000
):
found
=
False
for
i
,
op
in
enumerate
(
ops
):
for
dep
in
op
.
_auto_deps
:
if
dep
[
0
]
==
app_label
:
# Alright, there's a dependency on the same app.
for
j
,
op2
in
enumerate
(
ops
):
if
j
>
i
and
self
.
check_dependency
(
op2
,
dep
):
# shift the operation from position i after
# the operation at position j
ops
=
ops
[:
i
]
+
ops
[
i
+
1
:
j
+
1
]
+
[
op
]
+
ops
[
j
+
1
:]
found
=
True
break
if
found
:
break
if
found
:
break
if
not
found
:
break
else
:
raise
ValueError
(
"Infinite loop caught in operation dependency resolution"
)
self
.
generated_operations
[
app_label
]
=
ops
# construct a dependency-graph for in-app dependencies
dependency_graph
=
dict
((
op
,
set
())
for
op
in
ops
)
for
op
in
ops
:
for
dep
in
op
.
_auto_deps
:
if
dep
[
0
]
==
app_label
:
for
op2
in
ops
:
if
self
.
check_dependency
(
op2
,
dep
):
dependency_graph
[
op
]
.
add
(
op2
)
# we use a stable sort for deterministic tests & general behavior
self
.
generated_operations
[
app_label
]
=
stable_topological_sort
(
ops
,
dependency_graph
)
# Now, we need to chop the lists of operations up into migrations with
# dependencies on each other.
...
...
django/db/migrations/topological_sort.py
0 → 100644
Dosyayı görüntüle @
13d613f8
def
topological_sort_as_sets
(
dependency_graph
):
"""Variation of Kahn's algorithm (1962) that returns sets.
Takes a dependency graph as a dictionary of node => dependencies.
Yields sets of items in topological order, where the first set contains
all nodes without dependencies, and each following set contains all
nodes that depend on the nodes in the previously yielded sets.
"""
todo
=
dependency_graph
.
copy
()
while
todo
:
current
=
set
(
node
for
node
,
deps
in
todo
.
items
()
if
len
(
deps
)
==
0
)
if
not
current
:
raise
ValueError
(
'Cyclic dependency in graph: {}'
.
format
(
', '
.
join
(
repr
(
x
)
for
x
in
todo
.
items
())))
yield
current
# remove current from todo's nodes & dependencies
todo
=
{
node
:
(
dependencies
-
current
)
for
node
,
dependencies
in
todo
.
items
()
if
node
not
in
current
}
def
stable_topological_sort
(
l
,
dependency_graph
):
result
=
[]
for
layer
in
topological_sort_as_sets
(
dependency_graph
):
for
node
in
l
:
if
node
in
layer
:
result
.
append
(
node
)
return
result
tests/migrations/test_autodetector.py
Dosyayı görüntüle @
13d613f8
...
...
@@ -1107,12 +1107,12 @@ class AutodetectorTests(TestCase):
# Right number of migrations?
self
.
assertNumberMigrations
(
changes
,
"testapp"
,
1
)
# Right actions in right order?
self
.
assertOperationTypes
(
changes
,
"testapp"
,
0
,
[
"RemoveField"
,
"RemoveField"
,
"
DeleteModel"
,
"RemoveField
"
,
"DeleteModel"
])
self
.
assertOperationTypes
(
changes
,
"testapp"
,
0
,
[
"RemoveField"
,
"RemoveField"
,
"
RemoveField"
,
"DeleteModel
"
,
"DeleteModel"
])
# Actions touching the right stuff?
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
0
,
name
=
"publishers"
)
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
1
,
name
=
"author"
)
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
2
,
name
=
"
Autho
r"
)
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
3
,
name
=
"
publishe
r"
)
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
2
,
name
=
"
publishe
r"
)
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
3
,
name
=
"
Autho
r"
)
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
4
,
name
=
"Contract"
)
def
test_non_circular_foreignkey_dependency_removal
(
self
):
...
...
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