| 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)) |
|---|
| | 408 | |
|---|
| | 409 | def _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 |
|---|