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
8a3e543f
Kaydet (Commit)
8a3e543f
authored
Eyl 25, 2013
tarafından
Andrew Godwin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make sqlmigrate ignore the RunPython operation
üst
3b810c56
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
+25
-5
executor.py
django/db/migrations/executor.py
+2
-2
migration.py
django/db/migrations/migration.py
+20
-3
special.py
django/db/migrations/operations/special.py
+3
-0
No files found.
django/db/migrations/executor.py
Dosyayı görüntüle @
8a3e543f
...
...
@@ -71,9 +71,9 @@ class MigrationExecutor(object):
with
self
.
connection
.
schema_editor
(
collect_sql
=
True
)
as
schema_editor
:
project_state
=
self
.
loader
.
graph
.
project_state
((
migration
.
app_label
,
migration
.
name
),
at_end
=
False
)
if
not
backwards
:
migration
.
apply
(
project_state
,
schema_editor
)
migration
.
apply
(
project_state
,
schema_editor
,
collect_sql
=
True
)
else
:
migration
.
unapply
(
project_state
,
schema_editor
)
migration
.
unapply
(
project_state
,
schema_editor
,
collect_sql
=
True
)
statements
.
extend
(
schema_editor
.
collected_sql
)
return
statements
...
...
django/db/migrations/migration.py
Dosyayı görüntüle @
8a3e543f
...
...
@@ -67,7 +67,7 @@ class Migration(object):
operation
.
state_forwards
(
self
.
app_label
,
new_state
)
return
new_state
def
apply
(
self
,
project_state
,
schema_editor
):
def
apply
(
self
,
project_state
,
schema_editor
,
collect_sql
=
False
):
"""
Takes a project_state representing all migrations prior to this one
and a schema_editor for a live database and applies the migration
...
...
@@ -77,6 +77,14 @@ class Migration(object):
Migrations.
"""
for
operation
in
self
.
operations
:
# If this operation cannot be represented as SQL, place a comment
# there instead
if
collect_sql
and
not
operation
.
reduces_to_sql
:
schema_editor
.
collected_sql
.
append
(
"--"
)
schema_editor
.
collected_sql
.
append
(
"-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:"
)
schema_editor
.
collected_sql
.
append
(
"--
%
s"
%
operation
.
describe
())
schema_editor
.
collected_sql
.
append
(
"--"
)
continue
# Get the state after the operation has run
new_state
=
project_state
.
clone
()
operation
.
state_forwards
(
self
.
app_label
,
new_state
)
...
...
@@ -86,7 +94,7 @@ class Migration(object):
project_state
=
new_state
return
project_state
def
unapply
(
self
,
project_state
,
schema_editor
):
def
unapply
(
self
,
project_state
,
schema_editor
,
collect_sql
=
False
):
"""
Takes a project_state representing all migrations prior to this one
and a schema_editor for a live database and applies the migration
...
...
@@ -95,8 +103,17 @@ class Migration(object):
# We need to pre-calculate the stack of project states
to_run
=
[]
for
operation
in
self
.
operations
:
# If this operation cannot be represented as SQL, place a comment
# there instead
if
collect_sql
and
not
operation
.
reduces_to_sql
:
schema_editor
.
collected_sql
.
append
(
"--"
)
schema_editor
.
collected_sql
.
append
(
"-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:"
)
schema_editor
.
collected_sql
.
append
(
"--
%
s"
%
operation
.
describe
())
schema_editor
.
collected_sql
.
append
(
"--"
)
continue
# If it's irreversible, error out
if
not
operation
.
reversible
:
raise
Migration
.
IrreversibleError
(
"Operation
%
s in
%
s is not reversible"
%
(
operation
,
se
k
f
))
raise
Migration
.
IrreversibleError
(
"Operation
%
s in
%
s is not reversible"
%
(
operation
,
se
l
f
))
new_state
=
project_state
.
clone
()
operation
.
state_forwards
(
self
.
app_label
,
new_state
)
to_run
.
append
((
operation
,
project_state
,
new_state
))
...
...
django/db/migrations/operations/special.py
Dosyayı görüntüle @
8a3e543f
...
...
@@ -132,3 +132,6 @@ class RunPython(Operation):
def
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
raise
NotImplementedError
(
"You cannot reverse this operation"
)
def
describe
(
self
):
return
"Raw Python operation"
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