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
1d4bcb86
Kaydet (Commit)
1d4bcb86
authored
Ara 29, 2013
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Changed sql_* to use an app config instead of a models module.
üst
38ce4110
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
31 deletions
+31
-31
sql.py
django/core/management/commands/sql.py
+1
-1
sqlall.py
django/core/management/commands/sqlall.py
+1
-1
sqlclear.py
django/core/management/commands/sqlclear.py
+1
-1
sqlcustom.py
django/core/management/commands/sqlcustom.py
+1
-1
sqldropindexes.py
django/core/management/commands/sqldropindexes.py
+1
-1
sqlindexes.py
django/core/management/commands/sqlindexes.py
+1
-1
sql.py
django/core/management/sql.py
+13
-13
tests.py
tests/commands_sql/tests.py
+12
-12
No files found.
django/core/management/commands/sql.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
if
app_config
.
models_module
is
None
:
if
app_config
.
models_module
is
None
:
return
return
connection
=
connections
[
options
.
get
(
'database'
)]
connection
=
connections
[
options
.
get
(
'database'
)]
statements
=
sql_create
(
app_config
.
models_module
,
self
.
style
,
connection
)
statements
=
sql_create
(
app_config
,
self
.
style
,
connection
)
return
'
\n
'
.
join
(
statements
)
return
'
\n
'
.
join
(
statements
)
django/core/management/commands/sqlall.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
if
app_config
.
models_module
is
None
:
if
app_config
.
models_module
is
None
:
return
return
connection
=
connections
[
options
.
get
(
'database'
)]
connection
=
connections
[
options
.
get
(
'database'
)]
statements
=
sql_all
(
app_config
.
models_module
,
self
.
style
,
connection
)
statements
=
sql_all
(
app_config
,
self
.
style
,
connection
)
return
'
\n
'
.
join
(
statements
)
return
'
\n
'
.
join
(
statements
)
django/core/management/commands/sqlclear.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
if
app_config
.
models_module
is
None
:
if
app_config
.
models_module
is
None
:
return
return
connection
=
connections
[
options
.
get
(
'database'
)]
connection
=
connections
[
options
.
get
(
'database'
)]
statements
=
sql_delete
(
app_config
.
models_module
,
self
.
style
,
connection
)
statements
=
sql_delete
(
app_config
,
self
.
style
,
connection
)
return
'
\n
'
.
join
(
statements
)
return
'
\n
'
.
join
(
statements
)
django/core/management/commands/sqlcustom.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
...
@@ -22,5 +22,5 @@ class Command(AppCommand):
if
app_config
.
models_module
is
None
:
if
app_config
.
models_module
is
None
:
return
return
connection
=
connections
[
options
.
get
(
'database'
)]
connection
=
connections
[
options
.
get
(
'database'
)]
statements
=
sql_custom
(
app_config
.
models_module
,
self
.
style
,
connection
)
statements
=
sql_custom
(
app_config
,
self
.
style
,
connection
)
return
'
\n
'
.
join
(
statements
)
return
'
\n
'
.
join
(
statements
)
django/core/management/commands/sqldropindexes.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -23,5 +23,5 @@ class Command(AppCommand):
...
@@ -23,5 +23,5 @@ class Command(AppCommand):
if
app_config
.
models_module
is
None
:
if
app_config
.
models_module
is
None
:
return
return
connection
=
connections
[
options
.
get
(
'database'
)]
connection
=
connections
[
options
.
get
(
'database'
)]
statements
=
sql_destroy_indexes
(
app_config
.
models_module
,
self
.
style
,
connection
)
statements
=
sql_destroy_indexes
(
app_config
,
self
.
style
,
connection
)
return
'
\n
'
.
join
(
statements
)
return
'
\n
'
.
join
(
statements
)
django/core/management/commands/sqlindexes.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -23,5 +23,5 @@ class Command(AppCommand):
...
@@ -23,5 +23,5 @@ class Command(AppCommand):
if
app_config
.
models_module
is
None
:
if
app_config
.
models_module
is
None
:
return
return
connection
=
connections
[
options
.
get
(
'database'
)]
connection
=
connections
[
options
.
get
(
'database'
)]
statements
=
sql_indexes
(
app_config
.
models_module
,
self
.
style
,
connection
)
statements
=
sql_indexes
(
app_config
,
self
.
style
,
connection
)
return
'
\n
'
.
join
(
statements
)
return
'
\n
'
.
join
(
statements
)
django/core/management/sql.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -11,7 +11,7 @@ from django.core.management.base import CommandError
...
@@ -11,7 +11,7 @@ from django.core.management.base import CommandError
from
django.db
import
models
,
router
from
django.db
import
models
,
router
def
sql_create
(
app
,
style
,
connection
):
def
sql_create
(
app
_config
,
style
,
connection
):
"Returns a list of the CREATE TABLE SQL statements for the given app."
"Returns a list of the CREATE TABLE SQL statements for the given app."
if
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.dummy'
:
if
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.dummy'
:
...
@@ -25,13 +25,13 @@ def sql_create(app, style, connection):
...
@@ -25,13 +25,13 @@ def sql_create(app, style, connection):
# We trim models from the current app so that the sqlreset command does not
# We trim models from the current app so that the sqlreset command does not
# generate invalid SQL (leaving models out of known_models is harmless, so
# generate invalid SQL (leaving models out of known_models is harmless, so
# we can be conservative).
# we can be conservative).
app_models
=
app
s
.
get_models
(
app
,
include_auto_created
=
True
)
app_models
=
app
_config
.
get_models
(
include_auto_created
=
True
)
final_output
=
[]
final_output
=
[]
tables
=
connection
.
introspection
.
table_names
()
tables
=
connection
.
introspection
.
table_names
()
known_models
=
set
(
model
for
model
in
connection
.
introspection
.
installed_models
(
tables
)
if
model
not
in
app_models
)
known_models
=
set
(
model
for
model
in
connection
.
introspection
.
installed_models
(
tables
)
if
model
not
in
app_models
)
pending_references
=
{}
pending_references
=
{}
for
model
in
router
.
get_migratable_models
(
app
,
connection
.
alias
,
include_auto_created
=
True
):
for
model
in
router
.
get_migratable_models
(
app
_config
.
models_module
,
connection
.
alias
,
include_auto_created
=
True
):
output
,
references
=
connection
.
creation
.
sql_create_model
(
model
,
style
,
known_models
)
output
,
references
=
connection
.
creation
.
sql_create_model
(
model
,
style
,
known_models
)
final_output
.
extend
(
output
)
final_output
.
extend
(
output
)
for
refto
,
refs
in
references
.
items
():
for
refto
,
refs
in
references
.
items
():
...
@@ -57,7 +57,7 @@ def sql_create(app, style, connection):
...
@@ -57,7 +57,7 @@ def sql_create(app, style, connection):
return
final_output
return
final_output
def
sql_delete
(
app
,
style
,
connection
):
def
sql_delete
(
app
_config
,
style
,
connection
):
"Returns a list of the DROP TABLE SQL statements for the given app."
"Returns a list of the DROP TABLE SQL statements for the given app."
# This should work even if a connection isn't available
# This should work even if a connection isn't available
...
@@ -78,7 +78,7 @@ def sql_delete(app, style, connection):
...
@@ -78,7 +78,7 @@ def sql_delete(app, style, connection):
to_delete
=
set
()
to_delete
=
set
()
references_to_delete
=
{}
references_to_delete
=
{}
app_models
=
router
.
get_migratable_models
(
app
,
connection
.
alias
,
include_auto_created
=
True
)
app_models
=
router
.
get_migratable_models
(
app
_config
.
models_module
,
connection
.
alias
,
include_auto_created
=
True
)
for
model
in
app_models
:
for
model
in
app_models
:
if
cursor
and
connection
.
introspection
.
table_name_converter
(
model
.
_meta
.
db_table
)
in
table_names
:
if
cursor
and
connection
.
introspection
.
table_name_converter
(
model
.
_meta
.
db_table
)
in
table_names
:
# The table exists, so it needs to be dropped
# The table exists, so it needs to be dropped
...
@@ -118,11 +118,11 @@ def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_
...
@@ -118,11 +118,11 @@ def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_
return
statements
return
statements
def
sql_custom
(
app
,
style
,
connection
):
def
sql_custom
(
app
_config
,
style
,
connection
):
"Returns a list of the custom table modifying SQL statements for the given app."
"Returns a list of the custom table modifying SQL statements for the given app."
output
=
[]
output
=
[]
app_models
=
router
.
get_migratable_models
(
app
,
connection
.
alias
)
app_models
=
router
.
get_migratable_models
(
app
_config
.
models_module
,
connection
.
alias
)
for
model
in
app_models
:
for
model
in
app_models
:
output
.
extend
(
custom_sql_for_model
(
model
,
style
,
connection
))
output
.
extend
(
custom_sql_for_model
(
model
,
style
,
connection
))
...
@@ -130,25 +130,25 @@ def sql_custom(app, style, connection):
...
@@ -130,25 +130,25 @@ def sql_custom(app, style, connection):
return
output
return
output
def
sql_indexes
(
app
,
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."
"Returns a list of the CREATE INDEX SQL statements for all models in the given app."
output
=
[]
output
=
[]
for
model
in
router
.
get_migratable_models
(
app
,
connection
.
alias
,
include_auto_created
=
True
):
for
model
in
router
.
get_migratable_models
(
app
_config
.
models_module
,
connection
.
alias
,
include_auto_created
=
True
):
output
.
extend
(
connection
.
creation
.
sql_indexes_for_model
(
model
,
style
))
output
.
extend
(
connection
.
creation
.
sql_indexes_for_model
(
model
,
style
))
return
output
return
output
def
sql_destroy_indexes
(
app
,
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."
"Returns a list of the DROP INDEX SQL statements for all models in the given app."
output
=
[]
output
=
[]
for
model
in
router
.
get_migratable_models
(
app
,
connection
.
alias
,
include_auto_created
=
True
):
for
model
in
router
.
get_migratable_models
(
app
_config
.
models_module
,
connection
.
alias
,
include_auto_created
=
True
):
output
.
extend
(
connection
.
creation
.
sql_destroy_indexes_for_model
(
model
,
style
))
output
.
extend
(
connection
.
creation
.
sql_destroy_indexes_for_model
(
model
,
style
))
return
output
return
output
def
sql_all
(
app
,
style
,
connection
):
def
sql_all
(
app
_config
,
style
,
connection
):
"Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
"Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
return
sql_create
(
app
,
style
,
connection
)
+
sql_custom
(
app
,
style
,
connection
)
+
sql_indexes
(
app
,
style
,
connection
)
return
sql_create
(
app
_config
,
style
,
connection
)
+
sql_custom
(
app_config
,
style
,
connection
)
+
sql_indexes
(
app_config
,
style
,
connection
)
def
_split_statements
(
content
):
def
_split_statements
(
content
):
...
...
tests/commands_sql/tests.py
Dosyayı görüntüle @
1d4bcb86
...
@@ -17,8 +17,8 @@ class SQLCommandsTestCase(TestCase):
...
@@ -17,8 +17,8 @@ class SQLCommandsTestCase(TestCase):
return
len
([
o
for
o
in
output
if
o
.
startswith
(
cmd
)])
return
len
([
o
for
o
in
output
if
o
.
startswith
(
cmd
)])
def
test_sql_create
(
self
):
def
test_sql_create
(
self
):
app
=
apps
.
get_app_config
(
'commands_sql'
)
.
models_module
app
_config
=
apps
.
get_app_config
(
'commands_sql'
)
output
=
sql_create
(
app
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
output
=
sql_create
(
app
_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
create_tables
=
[
o
for
o
in
output
if
o
.
startswith
(
'CREATE TABLE'
)]
create_tables
=
[
o
for
o
in
output
if
o
.
startswith
(
'CREATE TABLE'
)]
self
.
assertEqual
(
len
(
create_tables
),
3
)
self
.
assertEqual
(
len
(
create_tables
),
3
)
# Lower so that Oracle's upper case tbl names wont break
# Lower so that Oracle's upper case tbl names wont break
...
@@ -26,8 +26,8 @@ class SQLCommandsTestCase(TestCase):
...
@@ -26,8 +26,8 @@ class SQLCommandsTestCase(TestCase):
six
.
assertRegex
(
self
,
sql
,
r'^create table .commands_sql_book.*'
)
six
.
assertRegex
(
self
,
sql
,
r'^create table .commands_sql_book.*'
)
def
test_sql_delete
(
self
):
def
test_sql_delete
(
self
):
app
=
apps
.
get_app_config
(
'commands_sql'
)
.
models_module
app
_config
=
apps
.
get_app_config
(
'commands_sql'
)
output
=
sql_delete
(
app
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
output
=
sql_delete
(
app
_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
drop_tables
=
[
o
for
o
in
output
if
o
.
startswith
(
'DROP TABLE'
)]
drop_tables
=
[
o
for
o
in
output
if
o
.
startswith
(
'DROP TABLE'
)]
self
.
assertEqual
(
len
(
drop_tables
),
3
)
self
.
assertEqual
(
len
(
drop_tables
),
3
)
# Lower so that Oracle's upper case tbl names wont break
# Lower so that Oracle's upper case tbl names wont break
...
@@ -35,20 +35,20 @@ class SQLCommandsTestCase(TestCase):
...
@@ -35,20 +35,20 @@ class SQLCommandsTestCase(TestCase):
six
.
assertRegex
(
self
,
sql
,
r'^drop table .commands_sql_comment.*'
)
six
.
assertRegex
(
self
,
sql
,
r'^drop table .commands_sql_comment.*'
)
def
test_sql_indexes
(
self
):
def
test_sql_indexes
(
self
):
app
=
apps
.
get_app_config
(
'commands_sql'
)
.
models_module
app
_config
=
apps
.
get_app_config
(
'commands_sql'
)
output
=
sql_indexes
(
app
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
output
=
sql_indexes
(
app
_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
# PostgreSQL creates one additional index for CharField
# PostgreSQL creates one additional index for CharField
self
.
assertIn
(
self
.
count_ddl
(
output
,
'CREATE INDEX'
),
[
3
,
4
])
self
.
assertIn
(
self
.
count_ddl
(
output
,
'CREATE INDEX'
),
[
3
,
4
])
def
test_sql_destroy_indexes
(
self
):
def
test_sql_destroy_indexes
(
self
):
app
=
apps
.
get_app_config
(
'commands_sql'
)
.
models_module
app
_config
=
apps
.
get_app_config
(
'commands_sql'
)
output
=
sql_destroy_indexes
(
app
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
output
=
sql_destroy_indexes
(
app
_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
# PostgreSQL creates one additional index for CharField
# PostgreSQL creates one additional index for CharField
self
.
assertIn
(
self
.
count_ddl
(
output
,
'DROP INDEX'
),
[
3
,
4
])
self
.
assertIn
(
self
.
count_ddl
(
output
,
'DROP INDEX'
),
[
3
,
4
])
def
test_sql_all
(
self
):
def
test_sql_all
(
self
):
app
=
apps
.
get_app_config
(
'commands_sql'
)
.
models_module
app
_config
=
apps
.
get_app_config
(
'commands_sql'
)
output
=
sql_all
(
app
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
output
=
sql_all
(
app
_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
self
.
assertEqual
(
self
.
count_ddl
(
output
,
'CREATE TABLE'
),
3
)
self
.
assertEqual
(
self
.
count_ddl
(
output
,
'CREATE TABLE'
),
3
)
# PostgreSQL creates one additional index for CharField
# PostgreSQL creates one additional index for CharField
...
@@ -69,8 +69,8 @@ class SQLCommandsRouterTestCase(TestCase):
...
@@ -69,8 +69,8 @@ class SQLCommandsRouterTestCase(TestCase):
router
.
routers
=
self
.
_old_routers
router
.
routers
=
self
.
_old_routers
def
test_router_honored
(
self
):
def
test_router_honored
(
self
):
app
=
apps
.
get_app_config
(
'commands_sql'
)
.
models_module
app
_config
=
apps
.
get_app_config
(
'commands_sql'
)
for
sql_command
in
(
sql_all
,
sql_create
,
sql_delete
,
sql_indexes
,
sql_destroy_indexes
):
for
sql_command
in
(
sql_all
,
sql_create
,
sql_delete
,
sql_indexes
,
sql_destroy_indexes
):
output
=
sql_command
(
app
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
output
=
sql_command
(
app
_config
,
no_style
(),
connections
[
DEFAULT_DB_ALIAS
])
self
.
assertEqual
(
len
(
output
),
0
,
self
.
assertEqual
(
len
(
output
),
0
,
"
%
s command is not honoring routers"
%
sql_command
.
__name__
)
"
%
s command is not honoring routers"
%
sql_command
.
__name__
)
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