Django

Code

Changeset 3890

Show
Ignore:
Timestamp:
10/03/06 08:05:10 (2 years ago)
Author:
russellm
Message:

Factored out per-model index generation code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management.py

    r3889 r3890  
    399399def get_sql_indexes(app): 
    400400    "Returns a list of the CREATE INDEX SQL statements for the given app." 
    401     from django.db import backend, models 
     401    from django.db import models 
    402402    output = [] 
    403  
    404403    for model in models.get_models(app): 
    405         for f in model._meta.fields: 
    406             if f.db_index: 
    407                 unique = f.unique and 'UNIQUE ' or '' 
    408                 output.append( 
    409                     style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \ 
    410                     style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \ 
    411                     style.SQL_KEYWORD('ON') + ' ' + \ 
    412                     style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \ 
    413                     "(%s);" % style.SQL_FIELD(backend.quote_name(f.column)) 
    414                 ) 
     404        output.extend(_get_sql_index(model)) 
    415405    return output 
    416406get_sql_indexes.help_doc = "Prints the CREATE INDEX SQL statements for the given model module name(s)." 
    417407get_sql_indexes.args = APP_ARGS 
     408 
     409def _get_sql_index(model): 
     410    "Returns the CREATE INDEX SQL statements for a specific model" 
     411    from django.db import backend 
     412    output = [] 
     413 
     414    for f in model._meta.fields: 
     415        if f.db_index: 
     416            unique = f.unique and 'UNIQUE ' or '' 
     417            output.append( 
     418                style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \ 
     419                style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \ 
     420                style.SQL_KEYWORD('ON') + ' ' + \ 
     421                style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \ 
     422                "(%s);" % style.SQL_FIELD(backend.quote_name(f.column)) 
     423            ) 
     424    return output 
    418425 
    419426def get_sql_all(app):