summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2006-10-03 13:05:10 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2006-10-03 13:05:10 +0000
commitd886e71f2bfed64cbfddebde1d8d24aa04034937 (patch)
treea63c9893699e0cb8df9d3d10ed340c439eee742c
parent67eabb9299925c0c84bb1b350512c73d170317e5 (diff)
Factored out per-model index generation code.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3890 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/management.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/django/core/management.py b/django/core/management.py
index 96ca2f757c..69e768d459 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -398,24 +398,31 @@ get_sql_sequence_reset.args = APP_ARGS
def get_sql_indexes(app):
"Returns a list of the CREATE INDEX SQL statements for the given app."
- from django.db import backend, models
+ from django.db import models
output = []
-
for model in models.get_models(app):
- for f in model._meta.fields:
- if f.db_index:
- unique = f.unique and 'UNIQUE ' or ''
- output.append(
- style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \
- style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \
- style.SQL_KEYWORD('ON') + ' ' + \
- style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \
- "(%s);" % style.SQL_FIELD(backend.quote_name(f.column))
- )
+ output.extend(_get_sql_index(model))
return output
get_sql_indexes.help_doc = "Prints the CREATE INDEX SQL statements for the given model module name(s)."
get_sql_indexes.args = APP_ARGS
+def _get_sql_index(model):
+ "Returns the CREATE INDEX SQL statements for a specific model"
+ from django.db import backend
+ output = []
+
+ for f in model._meta.fields:
+ if f.db_index:
+ unique = f.unique and 'UNIQUE ' or ''
+ output.append(
+ style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \
+ style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \
+ style.SQL_KEYWORD('ON') + ' ' + \
+ style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \
+ "(%s);" % style.SQL_FIELD(backend.quote_name(f.column))
+ )
+ return output
+
def get_sql_all(app):
"Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
return get_sql_create(app) + get_sql_initial_data(app) + get_sql_indexes(app)