summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-29 21:11:12 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-29 21:25:28 +0100
commit1d4bcb86eab521aa3f9dfc52e77d8a51448aa0f7 (patch)
treedec05fea657445452656bb18c421c3df624297b1
parent38ce41103fecf58418163b19403608988a291b56 (diff)
Changed sql_* to use an app config instead of a models module.
-rw-r--r--django/core/management/commands/sql.py2
-rw-r--r--django/core/management/commands/sqlall.py2
-rw-r--r--django/core/management/commands/sqlclear.py2
-rw-r--r--django/core/management/commands/sqlcustom.py2
-rw-r--r--django/core/management/commands/sqldropindexes.py2
-rw-r--r--django/core/management/commands/sqlindexes.py2
-rw-r--r--django/core/management/sql.py26
-rw-r--r--tests/commands_sql/tests.py24
8 files changed, 31 insertions, 31 deletions
diff --git a/django/core/management/commands/sql.py b/django/core/management/commands/sql.py
index b846cc7cd4..3fd081940d 100644
--- a/django/core/management/commands/sql.py
+++ b/django/core/management/commands/sql.py
@@ -22,5 +22,5 @@ class Command(AppCommand):
if app_config.models_module is None:
return
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)
diff --git a/django/core/management/commands/sqlall.py b/django/core/management/commands/sqlall.py
index b4e65487f4..69746f1c3d 100644
--- a/django/core/management/commands/sqlall.py
+++ b/django/core/management/commands/sqlall.py
@@ -22,5 +22,5 @@ class Command(AppCommand):
if app_config.models_module is None:
return
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)
diff --git a/django/core/management/commands/sqlclear.py b/django/core/management/commands/sqlclear.py
index 15efb7872b..e611390533 100644
--- a/django/core/management/commands/sqlclear.py
+++ b/django/core/management/commands/sqlclear.py
@@ -22,5 +22,5 @@ class Command(AppCommand):
if app_config.models_module is None:
return
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)
diff --git a/django/core/management/commands/sqlcustom.py b/django/core/management/commands/sqlcustom.py
index 0988654816..bfc6f395d4 100644
--- a/django/core/management/commands/sqlcustom.py
+++ b/django/core/management/commands/sqlcustom.py
@@ -22,5 +22,5 @@ class Command(AppCommand):
if app_config.models_module is None:
return
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)
diff --git a/django/core/management/commands/sqldropindexes.py b/django/core/management/commands/sqldropindexes.py
index ac8469c700..4bdb42d608 100644
--- a/django/core/management/commands/sqldropindexes.py
+++ b/django/core/management/commands/sqldropindexes.py
@@ -23,5 +23,5 @@ class Command(AppCommand):
if app_config.models_module is None:
return
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)
diff --git a/django/core/management/commands/sqlindexes.py b/django/core/management/commands/sqlindexes.py
index 0ff1ab3914..2f1fd8d103 100644
--- a/django/core/management/commands/sqlindexes.py
+++ b/django/core/management/commands/sqlindexes.py
@@ -23,5 +23,5 @@ class Command(AppCommand):
if app_config.models_module is None:
return
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)
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index 40becd34d7..6f98282a9c 100644
--- a/django/core/management/sql.py
+++ b/django/core/management/sql.py
@@ -11,7 +11,7 @@ from django.core.management.base import CommandError
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."
if connection.settings_dict['ENGINE'] == 'django.db.backends.dummy':
@@ -25,13 +25,13 @@ def sql_create(app, style, connection):
# 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
# we can be conservative).
- app_models = apps.get_models(app, include_auto_created=True)
+ app_models = app_config.get_models(include_auto_created=True)
final_output = []
tables = connection.introspection.table_names()
known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models)
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)
final_output.extend(output)
for refto, refs in references.items():
@@ -57,7 +57,7 @@ def sql_create(app, style, connection):
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."
# This should work even if a connection isn't available
@@ -78,7 +78,7 @@ def sql_delete(app, style, connection):
to_delete = set()
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:
if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names:
# 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_
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."
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:
output.extend(custom_sql_for_model(model, style, connection))
@@ -130,25 +130,25 @@ def sql_custom(app, style, connection):
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."
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))
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."
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))
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."
- 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):
diff --git a/tests/commands_sql/tests.py b/tests/commands_sql/tests.py
index 00f4017b9c..7ef28f83db 100644
--- a/tests/commands_sql/tests.py
+++ b/tests/commands_sql/tests.py
@@ -17,8 +17,8 @@ class SQLCommandsTestCase(TestCase):
return len([o for o in output if o.startswith(cmd)])
def test_sql_create(self):
- app = apps.get_app_config('commands_sql').models_module
- output = sql_create(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ app_config = apps.get_app_config('commands_sql')
+ output = sql_create(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
create_tables = [o for o in output if o.startswith('CREATE TABLE')]
self.assertEqual(len(create_tables), 3)
# Lower so that Oracle's upper case tbl names wont break
@@ -26,8 +26,8 @@ class SQLCommandsTestCase(TestCase):
six.assertRegex(self, sql, r'^create table .commands_sql_book.*')
def test_sql_delete(self):
- app = apps.get_app_config('commands_sql').models_module
- output = sql_delete(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ app_config = apps.get_app_config('commands_sql')
+ output = sql_delete(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
drop_tables = [o for o in output if o.startswith('DROP TABLE')]
self.assertEqual(len(drop_tables), 3)
# Lower so that Oracle's upper case tbl names wont break
@@ -35,20 +35,20 @@ class SQLCommandsTestCase(TestCase):
six.assertRegex(self, sql, r'^drop table .commands_sql_comment.*')
def test_sql_indexes(self):
- app = apps.get_app_config('commands_sql').models_module
- output = sql_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ app_config = apps.get_app_config('commands_sql')
+ output = sql_indexes(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
# PostgreSQL creates one additional index for CharField
self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4])
def test_sql_destroy_indexes(self):
- app = apps.get_app_config('commands_sql').models_module
- output = sql_destroy_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ app_config = apps.get_app_config('commands_sql')
+ output = sql_destroy_indexes(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
# PostgreSQL creates one additional index for CharField
self.assertIn(self.count_ddl(output, 'DROP INDEX'), [3, 4])
def test_sql_all(self):
- app = apps.get_app_config('commands_sql').models_module
- output = sql_all(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ app_config = apps.get_app_config('commands_sql')
+ output = sql_all(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
self.assertEqual(self.count_ddl(output, 'CREATE TABLE'), 3)
# PostgreSQL creates one additional index for CharField
@@ -69,8 +69,8 @@ class SQLCommandsRouterTestCase(TestCase):
router.routers = self._old_routers
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):
- 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,
"%s command is not honoring routers" % sql_command.__name__)