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
58411041
Kaydet (Commit)
58411041
authored
Eki 19, 2013
tarafından
Loic Bistuer
Kaydeden (comit)
Tim Graham
Eki 19, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21283 -- Added support for migrations if models is a package.
Thanks Markus Holtermann for the report.
üst
96d1d4e2
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
46 additions
and
13 deletions
+46
-13
loader.py
django/db/migrations/loader.py
+2
-2
writer.py
django/db/migrations/writer.py
+10
-8
loading.py
django/db/models/loading.py
+7
-0
__init__.py
tests/migrations/migrations_test_apps/__init__.py
+0
-0
__init__.py
tests/migrations/migrations_test_apps/normal/__init__.py
+0
-0
models.py
tests/migrations/migrations_test_apps/normal/models.py
+0
-0
__init__.py
...tions/migrations_test_apps/with_package_model/__init__.py
+0
-0
__init__.py
...igrations_test_apps/with_package_model/models/__init__.py
+0
-0
test_writer.py
tests/migrations/test_writer.py
+27
-3
No files found.
django/db/migrations/loader.py
Dosyayı görüntüle @
58411041
...
...
@@ -41,8 +41,8 @@ class MigrationLoader(object):
def
migrations_module
(
cls
,
app_label
):
if
app_label
in
settings
.
MIGRATION_MODULES
:
return
settings
.
MIGRATION_MODULES
[
app_label
]
app
=
cache
.
get_app
(
app_label
)
return
"."
.
join
(
app
.
__name__
.
split
(
"."
)[:
-
1
]
+
[
"migrations"
]
)
else
:
return
'
%
s.migrations'
%
cache
.
get_app_package
(
app_label
)
def
load_disk
(
self
):
"""
...
...
django/db/migrations/writer.py
Dosyayı görüntüle @
58411041
...
...
@@ -61,20 +61,22 @@ class MigrationWriter(object):
@property
def
path
(
self
):
migrations_module_name
=
MigrationLoader
.
migrations_module
(
self
.
migration
.
app_label
)
app_module
=
cache
.
get_app
(
self
.
migration
.
app_label
)
migrations_package_name
=
MigrationLoader
.
migrations_module
(
self
.
migration
.
app_label
)
# See if we can import the migrations module directly
try
:
migrations_module
=
import_module
(
migrations_
modul
e_name
)
migrations_module
=
import_module
(
migrations_
packag
e_name
)
basedir
=
os
.
path
.
dirname
(
migrations_module
.
__file__
)
except
ImportError
:
app
=
cache
.
get_app
(
self
.
migration
.
app_label
)
app_path
=
cache
.
_get_app_path
(
app
)
app_package_name
=
cache
.
_get_app_package
(
app
)
migrations_package_basename
=
migrations_package_name
.
split
(
"."
)[
-
1
]
# Alright, see if it's a direct submodule of the app
oneup
=
"."
.
join
(
migrations_module_name
.
split
(
"."
)[:
-
1
])
app_oneup
=
"."
.
join
(
app_module
.
__name__
.
split
(
"."
)[:
-
1
])
if
oneup
==
app_oneup
:
basedir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
app_module
.
__file__
),
migrations_module_name
.
split
(
"."
)[
-
1
])
if
'
%
s.
%
s'
%
(
app_package_name
,
migrations_package_basename
)
==
migrations_package_name
:
basedir
=
os
.
path
.
join
(
app_path
,
migrations_package_basename
)
else
:
raise
ImportError
(
"Cannot open migrations module
%
s for app
%
s"
%
(
migrations_
modul
e_name
,
self
.
migration
.
app_label
))
raise
ImportError
(
"Cannot open migrations module
%
s for app
%
s"
%
(
migrations_
packag
e_name
,
self
.
migration
.
app_label
))
return
os
.
path
.
join
(
basedir
,
self
.
filename
)
@classmethod
...
...
django/db/models/loading.py
Dosyayı görüntüle @
58411041
...
...
@@ -185,6 +185,12 @@ class BaseAppCache(object):
return
[
elt
[
0
]
for
elt
in
apps
]
def
_get_app_package
(
self
,
app
):
return
'.'
.
join
(
app
.
__name__
.
split
(
'.'
)[:
-
1
])
def
get_app_package
(
self
,
app_label
):
return
self
.
_get_app_package
(
self
.
get_app
(
app_label
))
def
_get_app_path
(
self
,
app
):
if
hasattr
(
app
,
'__path__'
):
# models/__init__.py package
app_path
=
app
.
__path__
[
0
]
...
...
@@ -380,6 +386,7 @@ cache = AppCache()
# These methods were always module level, so are kept that way for backwards
# compatibility.
get_apps
=
cache
.
get_apps
get_app_package
=
cache
.
get_app_package
get_app_path
=
cache
.
get_app_path
get_app_paths
=
cache
.
get_app_paths
get_app
=
cache
.
get_app
...
...
tests/migrations/migrations_test_apps/__init__.py
0 → 100644
Dosyayı görüntüle @
58411041
tests/migrations/migrations_test_apps/normal/__init__.py
0 → 100644
Dosyayı görüntüle @
58411041
tests/migrations/migrations_test_apps/normal/models.py
0 → 100644
Dosyayı görüntüle @
58411041
tests/migrations/migrations_test_apps/with_package_model/__init__.py
0 → 100644
Dosyayı görüntüle @
58411041
tests/migrations/migrations_test_apps/with_package_model/models/__init__.py
0 → 100644
Dosyayı görüntüle @
58411041
tests/migrations/test_writer.py
Dosyayı görüntüle @
58411041
...
...
@@ -2,12 +2,15 @@
from
__future__
import
unicode_literals
import
copy
import
datetime
import
os
from
django.utils
import
six
from
django.test
import
TestCase
from
django.db.migrations.writer
import
MigrationWriter
from
django.db
import
models
,
migrations
from
django.db.migrations.writer
import
MigrationWriter
from
django.db.models.loading
import
cache
from
django.test
import
TestCase
,
override_settings
from
django.utils
import
six
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -95,3 +98,24 @@ class WriterTests(TestCase):
# Just make sure it runs for now, and that things look alright.
result
=
self
.
safe_exec
(
output
)
self
.
assertIn
(
"Migration"
,
result
)
def
test_migration_path
(
self
):
_old_app_store
=
copy
.
deepcopy
(
cache
.
app_store
)
test_apps
=
[
'migrations.migrations_test_apps.normal'
,
'migrations.migrations_test_apps.with_package_model'
,
]
base_dir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
try
:
with
override_settings
(
INSTALLED_APPS
=
test_apps
):
for
app
in
test_apps
:
cache
.
load_app
(
app
)
migration
=
migrations
.
Migration
(
'0001_initial'
,
app
.
split
(
'.'
)[
-
1
])
expected_path
=
os
.
path
.
join
(
base_dir
,
*
(
app
.
split
(
'.'
)
+
[
'migrations'
,
'0001_initial.py'
]))
writer
=
MigrationWriter
(
migration
)
self
.
assertEqual
(
writer
.
path
,
expected_path
)
finally
:
cache
.
app_store
=
_old_app_store
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