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
7c54f8cc
Kaydet (Commit)
7c54f8cc
authored
Nis 30, 2014
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22474 -- Made migration recorder aware of multiple databases
Thanks Tim Graham for the review.
üst
7fd1b35e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
recorder.py
django/db/migrations/recorder.py
+14
-6
test_loader.py
tests/migrations/test_loader.py
+7
-1
No files found.
django/db/migrations/recorder.py
Dosyayı görüntüle @
7c54f8cc
from
django.apps.registry
import
Apps
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils.timezone
import
now
...
...
@@ -16,6 +17,7 @@ class MigrationRecorder(object):
a row in the table always means a migration is applied.
"""
@python_2_unicode_compatible
class
Migration
(
models
.
Model
):
app
=
models
.
CharField
(
max_length
=
255
)
name
=
models
.
CharField
(
max_length
=
255
)
...
...
@@ -26,9 +28,16 @@ class MigrationRecorder(object):
app_label
=
"migrations"
db_table
=
"django_migrations"
def
__str__
(
self
):
return
"Migration
%
s for
%
s"
%
(
self
.
name
,
self
.
app
)
def
__init__
(
self
,
connection
):
self
.
connection
=
connection
@property
def
migration_qs
(
self
):
return
self
.
Migration
.
objects
.
using
(
self
.
connection
.
alias
)
def
ensure_schema
(
self
):
"""
Ensures the table exists and has the correct schema.
...
...
@@ -46,25 +55,24 @@ class MigrationRecorder(object):
Returns a set of (app, name) of applied migrations.
"""
self
.
ensure_schema
()
return
set
(
tuple
(
x
)
for
x
in
self
.
Migration
.
object
s
.
values_list
(
"app"
,
"name"
))
return
set
(
tuple
(
x
)
for
x
in
self
.
migration_q
s
.
values_list
(
"app"
,
"name"
))
def
record_applied
(
self
,
app
,
name
):
"""
Records that a migration was applied.
"""
self
.
ensure_schema
()
self
.
Migration
.
object
s
.
create
(
app
=
app
,
name
=
name
)
self
.
migration_q
s
.
create
(
app
=
app
,
name
=
name
)
def
record_unapplied
(
self
,
app
,
name
):
"""
Records that a migration was unapplied.
"""
self
.
ensure_schema
()
self
.
Migration
.
object
s
.
filter
(
app
=
app
,
name
=
name
)
.
delete
()
self
.
migration_q
s
.
filter
(
app
=
app
,
name
=
name
)
.
delete
()
@classmethod
def
flush
(
cls
):
def
flush
(
self
):
"""
Deletes all migration records. Useful if you're testing migrations.
"""
cls
.
Migration
.
object
s
.
all
()
.
delete
()
self
.
migration_q
s
.
all
()
.
delete
()
tests/migrations/test_loader.py
Dosyayı görüntüle @
7c54f8cc
from
unittest
import
skipIf
from
django.test
import
TestCase
,
override_settings
from
django.db
import
connection
from
django.db
import
connection
,
connections
from
django.db.migrations.loader
import
MigrationLoader
,
AmbiguityError
from
django.db.migrations.recorder
import
MigrationRecorder
from
django.utils
import
six
...
...
@@ -26,6 +26,12 @@ class RecorderTests(TestCase):
recorder
.
applied_migrations
(),
set
([(
"myapp"
,
"0432_ponies"
)]),
)
# That should not affect records of another database
recorder_other
=
MigrationRecorder
(
connections
[
'other'
])
self
.
assertEqual
(
recorder_other
.
applied_migrations
(),
set
(),
)
recorder
.
record_unapplied
(
"myapp"
,
"0432_ponies"
)
self
.
assertEqual
(
recorder
.
applied_migrations
(),
...
...
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