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
e03b7940
Kaydet (Commit)
e03b7940
authored
Eyl 01, 2014
tarafından
Dave Hall
Kaydeden (comit)
Tim Graham
Eyl 02, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22918 -- Fixed SeparateDatabaseAndState crash
üst
03c1a6cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
special.py
django/db/migrations/operations/special.py
+2
-2
test_operations.py
tests/migrations/test_operations.py
+33
-0
No files found.
django/db/migrations/operations/special.py
Dosyayı görüntüle @
e03b7940
...
...
@@ -24,7 +24,7 @@ class SeparateDatabaseAndState(Operation):
for
database_operation
in
self
.
database_operations
:
to_state
=
from_state
.
clone
()
database_operation
.
state_forwards
(
app_label
,
to_state
)
database_operation
.
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
)
database_operation
.
database_forwards
(
app_label
,
schema_editor
,
from_state
,
to_state
)
from_state
=
to_state
def
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
...
...
@@ -36,7 +36,7 @@ class SeparateDatabaseAndState(Operation):
dbop
.
state_forwards
(
app_label
,
to_state
)
from_state
=
base_state
.
clone
()
database_operation
.
state_forwards
(
app_label
,
from_state
)
database_operation
.
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
)
database_operation
.
database_backwards
(
app_label
,
schema_editor
,
from_state
,
to_state
)
def
describe
(
self
):
return
"Custom state/database change combination"
...
...
tests/migrations/test_operations.py
Dosyayı görüntüle @
e03b7940
...
...
@@ -1278,6 +1278,39 @@ class OperationTests(OperationTestBase):
non_atomic_migration
.
apply
(
project_state
,
editor
)
self
.
assertEqual
(
project_state
.
render
()
.
get_model
(
"test_runpythonatomic"
,
"Pony"
)
.
objects
.
count
(),
1
)
@unittest.skipIf
(
sqlparse
is
None
and
connection
.
features
.
requires_sqlparse_for_splitting
,
"Missing sqlparse"
)
def
test_separate_database_and_state
(
self
):
"""
Tests the SeparateDatabaseAndState operation.
"""
project_state
=
self
.
set_up_test_model
(
"test_separatedatabaseandstate"
)
# Create the operation
database_operation
=
migrations
.
RunSQL
(
"CREATE TABLE i_love_ponies (id int, special_thing int);"
,
"DROP TABLE i_love_ponies;"
)
state_operation
=
migrations
.
CreateModel
(
"SomethingElse"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
))])
operation
=
migrations
.
SeparateDatabaseAndState
(
state_operations
=
[
state_operation
],
database_operations
=
[
database_operation
]
)
self
.
assertEqual
(
operation
.
describe
(),
"Custom state/database change combination"
)
# Test the state alteration
new_state
=
project_state
.
clone
()
operation
.
state_forwards
(
"test_separatedatabaseandstate"
,
new_state
)
self
.
assertEqual
(
len
(
new_state
.
models
[
"test_separatedatabaseandstate"
,
"somethingelse"
]
.
fields
),
1
)
# Make sure there's no table
self
.
assertTableNotExists
(
"i_love_ponies"
)
# Test the database alteration
with
connection
.
schema_editor
()
as
editor
:
operation
.
database_forwards
(
"test_separatedatabaseandstate"
,
editor
,
project_state
,
new_state
)
self
.
assertTableExists
(
"i_love_ponies"
)
# And test reversal
self
.
assertTrue
(
operation
.
reversible
)
with
connection
.
schema_editor
()
as
editor
:
operation
.
database_backwards
(
"test_separatedatabaseandstate"
,
editor
,
new_state
,
project_state
)
self
.
assertTableNotExists
(
"i_love_ponies"
)
class
MigrateNothingRouter
(
object
):
"""
...
...
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