diff options
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/management/commands/sqldropindexes.py | 23 | ||||
| -rw-r--r-- | django/core/management/sql.py | 7 |
2 files changed, 30 insertions, 0 deletions
diff --git a/django/core/management/commands/sqldropindexes.py b/django/core/management/commands/sqldropindexes.py new file mode 100644 index 0000000000..fce77211fb --- /dev/null +++ b/django/core/management/commands/sqldropindexes.py @@ -0,0 +1,23 @@ +from __future__ import unicode_literals + +from optparse import make_option + +from django.core.management.base import AppCommand +from django.core.management.sql import sql_destroy_indexes +from django.db import connections, DEFAULT_DB_ALIAS + +class Command(AppCommand): + help = "Prints the DROP INDEX SQL statements for the given model module name(s)." + + option_list = AppCommand.option_list + ( + make_option('--database', action='store', dest='database', + default=DEFAULT_DB_ALIAS, help='Nominates a database to print the ' + 'SQL for. Defaults to the "default" database.'), + + ) + + output_transaction = True + + def handle_app(self, app, **options): + return '\n'.join(sql_destroy_indexes(app, self.style, connections[options.get('database')])) + diff --git a/django/core/management/sql.py b/django/core/management/sql.py index 66df43e971..ac60ed470c 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -137,6 +137,13 @@ def sql_indexes(app, style, connection): output.extend(connection.creation.sql_indexes_for_model(model, style)) return output +def sql_destroy_indexes(app, style, connection): + "Returns a list of the DROP INDEX SQL statements for all models in the given app." + output = [] + for model in models.get_models(app): + output.extend(connection.creation.sql_destroy_indexes_for_model(model, style)) + return output + def sql_all(app, style, connection): "Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module." |
