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
cb9c9a7b
Kaydet (Commit)
cb9c9a7b
authored
May 29, 2014
tarafından
Víðir Valberg Guðmundsson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Making SQL management commands migration aware.
üst
62f9508a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
107 additions
and
0 deletions
+107
-0
sqlsequencereset.py
django/core/management/commands/sqlsequencereset.py
+2
-0
sql.py
django/core/management/sql.py
+23
-0
__init__.py
tests/commands_sql_migrations/__init__.py
+0
-0
0001_initial.py
tests/commands_sql_migrations/migrations/0001_initial.py
+33
-0
__init__.py
tests/commands_sql_migrations/migrations/__init__.py
+0
-0
models.py
tests/commands_sql_migrations/models.py
+10
-0
tests.py
tests/commands_sql_migrations/tests.py
+39
-0
No files found.
django/core/management/commands/sqlsequencereset.py
Dosyayı görüntüle @
cb9c9a7b
...
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from
optparse
import
make_option
from
django.core.management.base
import
AppCommand
from
django.core.management.sql
import
check_for_migrations
from
django.db
import
connections
,
DEFAULT_DB_ALIAS
...
...
@@ -22,6 +23,7 @@ class Command(AppCommand):
if
app_config
.
models_module
is
None
:
return
connection
=
connections
[
options
.
get
(
'database'
)]
check_for_migrations
(
app_config
,
connection
)
models
=
app_config
.
get_models
(
include_auto_created
=
True
)
statements
=
connection
.
ops
.
sequence_reset_sql
(
self
.
style
,
models
)
return
'
\n
'
.
join
(
statements
)
django/core/management/sql.py
Dosyayı görüntüle @
cb9c9a7b
...
...
@@ -9,12 +9,21 @@ from django.apps import apps
from
django.conf
import
settings
from
django.core.management.base
import
CommandError
from
django.db
import
models
,
router
from
django.db.migrations.loader
import
MigrationLoader
from
django.utils.deprecation
import
RemovedInDjango19Warning
def
check_for_migrations
(
app_config
,
connection
):
loader
=
MigrationLoader
(
connection
)
if
app_config
.
label
in
loader
.
migrated_apps
:
raise
CommandError
(
"App '
%
s' has migrations. Only the sqlmigrate and sqlflush commands can be used when an app has migrations."
%
app_config
.
label
)
def
sql_create
(
app_config
,
style
,
connection
):
"Returns a list of the CREATE TABLE SQL statements for the given app."
check_for_migrations
(
app_config
,
connection
)
if
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.dummy'
:
# This must be the "dummy" database backend, which means the user
# hasn't set ENGINE for the database.
...
...
@@ -61,6 +70,8 @@ def sql_create(app_config, style, connection):
def
sql_delete
(
app_config
,
style
,
connection
):
"Returns a list of the DROP TABLE SQL statements for the given app."
check_for_migrations
(
app_config
,
connection
)
# This should work even if a connection isn't available
try
:
cursor
=
connection
.
cursor
()
...
...
@@ -122,6 +133,9 @@ def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_
def
sql_custom
(
app_config
,
style
,
connection
):
"Returns a list of the custom table modifying SQL statements for the given app."
check_for_migrations
(
app_config
,
connection
)
output
=
[]
app_models
=
router
.
get_migratable_models
(
app_config
,
connection
.
alias
)
...
...
@@ -134,6 +148,9 @@ def sql_custom(app_config, style, connection):
def
sql_indexes
(
app_config
,
style
,
connection
):
"Returns a list of the CREATE INDEX SQL statements for all models in the given app."
check_for_migrations
(
app_config
,
connection
)
output
=
[]
for
model
in
router
.
get_migratable_models
(
app_config
,
connection
.
alias
,
include_auto_created
=
True
):
output
.
extend
(
connection
.
creation
.
sql_indexes_for_model
(
model
,
style
))
...
...
@@ -142,6 +159,9 @@ def sql_indexes(app_config, style, connection):
def
sql_destroy_indexes
(
app_config
,
style
,
connection
):
"Returns a list of the DROP INDEX SQL statements for all models in the given app."
check_for_migrations
(
app_config
,
connection
)
output
=
[]
for
model
in
router
.
get_migratable_models
(
app_config
,
connection
.
alias
,
include_auto_created
=
True
):
output
.
extend
(
connection
.
creation
.
sql_destroy_indexes_for_model
(
model
,
style
))
...
...
@@ -149,6 +169,9 @@ def sql_destroy_indexes(app_config, style, connection):
def
sql_all
(
app_config
,
style
,
connection
):
check_for_migrations
(
app_config
,
connection
)
"Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
return
sql_create
(
app_config
,
style
,
connection
)
+
sql_custom
(
app_config
,
style
,
connection
)
+
sql_indexes
(
app_config
,
style
,
connection
)
...
...
tests/commands_sql_migrations/__init__.py
0 → 100644
Dosyayı görüntüle @
cb9c9a7b
tests/commands_sql_migrations/migrations/0001_initial.py
0 → 100644
Dosyayı görüntüle @
cb9c9a7b
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Comment'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
serialize
=
False
,
auto_created
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
migrations
.
CreateModel
(
name
=
'Book'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
serialize
=
False
,
auto_created
=
True
)),
(
'title'
,
models
.
CharField
(
db_index
=
True
,
max_length
=
100
)),
(
'comments'
,
models
.
ManyToManyField
(
to
=
'commands_sql_migrations.Comment'
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
tests/commands_sql_migrations/migrations/__init__.py
0 → 100644
Dosyayı görüntüle @
cb9c9a7b
tests/commands_sql_migrations/models.py
0 → 100644
Dosyayı görüntüle @
cb9c9a7b
from
django.db
import
models
class
Comment
(
models
.
Model
):
pass
class
Book
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
,
db_index
=
True
)
comments
=
models
.
ManyToManyField
(
Comment
)
tests/commands_sql_migrations/tests.py
0 → 100644
Dosyayı görüntüle @
cb9c9a7b
from
__future__
import
unicode_literals
from
django.apps
import
apps
from
django.core.management
import
CommandError
from
django.core.management.color
import
no_style
from
django.core.management.sql
import
(
sql_create
,
sql_delete
,
sql_indexes
,
sql_destroy_indexes
,
sql_all
)
from
django.db
import
connections
,
DEFAULT_DB_ALIAS
,
router
from
django.test
import
TestCase
class
SQLCommandsMigrationsTestCase
(
TestCase
):
"""Tests that apps with migrations can not use sql commands."""
def
test_sql_create
(
self
):
app_config
=
apps
.
get_app_config
(
'commands_sql_migrations'
)
with
self
.
assertRaises
(
CommandError
):
sql_create
(
app_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
def
test_sql_delete
(
self
):
app_config
=
apps
.
get_app_config
(
'commands_sql_migrations'
)
with
self
.
assertRaises
(
CommandError
):
sql_delete
(
app_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
def
test_sql_indexes
(
self
):
app_config
=
apps
.
get_app_config
(
'commands_sql_migrations'
)
with
self
.
assertRaises
(
CommandError
):
sql_indexes
(
app_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
def
test_sql_destroy_indexes
(
self
):
app_config
=
apps
.
get_app_config
(
'commands_sql_migrations'
)
with
self
.
assertRaises
(
CommandError
):
sql_destroy_indexes
(
app_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
def
test_sql_all
(
self
):
app_config
=
apps
.
get_app_config
(
'commands_sql_migrations'
)
with
self
.
assertRaises
(
CommandError
):
sql_all
(
app_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
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