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
819d5f0c
Kaydet (Commit)
819d5f0c
authored
Haz 18, 2014
tarafından
Andrew Godwin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[1.7.x] Fixed #22861: Internal migrations done first so __first__ works
Thanks to Chris Beaven.
üst
1122d297
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
145 additions
and
6 deletions
+145
-6
graph.py
django/db/migrations/graph.py
+2
-2
loader.py
django/db/migrations/loader.py
+11
-0
test_graph.py
tests/migrations/test_graph.py
+4
-4
test_loader.py
tests/migrations/test_loader.py
+20
-0
__init__.py
tests/migrations/test_migrations_first/__init__.py
+0
-0
second.py
tests/migrations/test_migrations_first/second.py
+30
-0
thefirst.py
tests/migrations/test_migrations_first/thefirst.py
+30
-0
0001_initial.py
tests/migrations2/test_migrations_2_first/0001_initial.py
+26
-0
0002_second.py
tests/migrations2/test_migrations_2_first/0002_second.py
+22
-0
__init__.py
tests/migrations2/test_migrations_2_first/__init__.py
+0
-0
No files found.
django/db/migrations/graph.py
Dosyayı görüntüle @
819d5f0c
...
...
@@ -74,7 +74,7 @@ class MigrationGraph(object):
for
node
in
self
.
nodes
:
if
not
any
(
key
[
0
]
==
node
[
0
]
for
key
in
self
.
dependencies
.
get
(
node
,
set
()))
and
(
not
app
or
app
==
node
[
0
]):
roots
.
add
(
node
)
return
roots
return
sorted
(
roots
)
def
leaf_nodes
(
self
,
app
=
None
):
"""
...
...
@@ -88,7 +88,7 @@ class MigrationGraph(object):
for
node
in
self
.
nodes
:
if
not
any
(
key
[
0
]
==
node
[
0
]
for
key
in
self
.
dependents
.
get
(
node
,
set
()))
and
(
not
app
or
app
==
node
[
0
]):
leaves
.
add
(
node
)
return
leaves
return
sorted
(
leaves
)
def
dfs
(
self
,
start
,
get_children
):
"""
...
...
django/db/migrations/loader.py
Dosyayı görüntüle @
819d5f0c
...
...
@@ -223,8 +223,19 @@ class MigrationLoader(object):
self
.
graph
=
MigrationGraph
()
for
key
,
migration
in
normal
.
items
():
self
.
graph
.
add_node
(
key
,
migration
)
# Add all internal dependencies first to ensure __first__ dependencies
# find the correct root node.
for
key
,
migration
in
normal
.
items
():
for
parent
in
migration
.
dependencies
:
if
parent
[
0
]
!=
key
[
0
]
or
parent
[
1
]
==
'__first__'
:
# Ignore __first__ references to the same app (#22325)
continue
self
.
graph
.
add_dependency
(
key
,
parent
)
for
key
,
migration
in
normal
.
items
():
for
parent
in
migration
.
dependencies
:
if
parent
[
0
]
==
key
[
0
]:
# Internal dependencies already added.
continue
parent
=
self
.
check_key
(
parent
,
key
[
0
])
if
parent
is
not
None
:
self
.
graph
.
add_dependency
(
key
,
parent
)
...
...
tests/migrations/test_graph.py
Dosyayı görüntüle @
819d5f0c
...
...
@@ -51,11 +51,11 @@ class GraphTests(TestCase):
# Test roots and leaves
self
.
assertEqual
(
graph
.
root_nodes
(),
set
([(
'app_a'
,
'0001'
),
(
'app_b'
,
'0001'
)])
,
[(
'app_a'
,
'0001'
),
(
'app_b'
,
'0001'
)]
,
)
self
.
assertEqual
(
graph
.
leaf_nodes
(),
set
([(
'app_a'
,
'0004'
),
(
'app_b'
,
'0002'
)])
,
[(
'app_a'
,
'0004'
),
(
'app_b'
,
'0002'
)]
,
)
def
test_complex_graph
(
self
):
...
...
@@ -105,11 +105,11 @@ class GraphTests(TestCase):
# Test roots and leaves
self
.
assertEqual
(
graph
.
root_nodes
(),
set
([(
'app_a'
,
'0001'
),
(
'app_b'
,
'0001'
),
(
'app_c'
,
'0001'
)])
,
[(
'app_a'
,
'0001'
),
(
'app_b'
,
'0001'
),
(
'app_c'
,
'0001'
)]
,
)
self
.
assertEqual
(
graph
.
leaf_nodes
(),
set
([(
'app_a'
,
'0004'
),
(
'app_b'
,
'0002'
),
(
'app_c'
,
'0002'
)])
,
[(
'app_a'
,
'0004'
),
(
'app_b'
,
'0002'
),
(
'app_c'
,
'0002'
)]
,
)
def
test_circular_graph
(
self
):
...
...
tests/migrations/test_loader.py
Dosyayı görüntüle @
819d5f0c
...
...
@@ -142,6 +142,26 @@ class LoaderTests(TestCase):
],
)
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_first"
,
"migrations2"
:
"migrations2.test_migrations_2_first"
,
})
@modify_settings
(
INSTALLED_APPS
=
{
'append'
:
'migrations2'
})
def
test_first
(
self
):
"""
Makes sure the '__first__' migrations build correctly.
"""
migration_loader
=
MigrationLoader
(
connection
)
self
.
assertEqual
(
migration_loader
.
graph
.
forwards_plan
((
"migrations"
,
"second"
)),
[
(
"migrations"
,
"thefirst"
),
(
"migrations2"
,
"0001_initial"
),
(
"migrations2"
,
"0002_second"
),
(
"migrations"
,
"second"
),
],
)
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations"
})
def
test_name_match
(
self
):
"Tests prefix name matching"
...
...
tests/migrations/test_migrations_first/__init__.py
0 → 100644
Dosyayı görüntüle @
819d5f0c
tests/migrations/test_migrations_first/second.py
0 → 100644
Dosyayı görüntüle @
819d5f0c
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
"migrations"
,
"thefirst"
),
(
"migrations2"
,
"0002_second"
),
]
operations
=
[
migrations
.
DeleteModel
(
"Tribble"
),
migrations
.
RemoveField
(
"Author"
,
"silly_field"
),
migrations
.
AddField
(
"Author"
,
"rating"
,
models
.
IntegerField
(
default
=
0
)),
migrations
.
CreateModel
(
"Book"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"author"
,
models
.
ForeignKey
(
"migrations.Author"
,
null
=
True
)),
],
)
]
tests/migrations/test_migrations_first/thefirst.py
0 → 100644
Dosyayı görüntüle @
819d5f0c
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
operations
=
[
migrations
.
CreateModel
(
"Author"
,
[
(
"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
)),
],
),
migrations
.
CreateModel
(
"Tribble"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"fluffy"
,
models
.
BooleanField
(
default
=
True
)),
],
)
]
tests/migrations2/test_migrations_2_first/0001_initial.py
0 → 100644
Dosyayı görüntüle @
819d5f0c
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
"migrations"
,
"__first__"
),
]
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/migrations2/test_migrations_2_first/0002_second.py
0 → 100644
Dosyayı görüntüle @
819d5f0c
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[(
"migrations2"
,
"0001_initial"
)]
operations
=
[
migrations
.
CreateModel
(
"Bookstore"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
255
)),
(
"slug"
,
models
.
SlugField
(
null
=
True
)),
],
),
]
tests/migrations2/test_migrations_2_first/__init__.py
0 → 100644
Dosyayı görüntüle @
819d5f0c
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