from django.conf import settings
from .operations import DatabaseOperations
from .introspection import DatabaseIntrospection
+from .creation import DatabaseCreation
class DatabaseWrapper(DatabaseWrapper):
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.ops = DatabaseOperations()
+ self.creation = DatabaseCreation(self)
self.introspection = DatabaseIntrospection(self)
def _cursor(self):
--- /dev/null
+from django.db.backends.postgresql.creation import DatabaseCreation as PgDatabaseCreation
+
+class DatabaseCreation(PgDatabaseCreation):
+
+ def sql_indexes_for_field(self, model, f, style):
+ "Return the CREATE INDEX SQL statements for a single model field"
+ if f.db_index and not f.unique:
+ qn = self.connection.ops.quote_name
+ tablespace = f.db_tablespace or model._meta.db_tablespace
+ if tablespace:
+ sql = self.connection.ops.tablespace_sql(tablespace)
+ if sql:
+ tablespace_sql = ' ' + sql
+ else:
+ tablespace_sql = ''
+ else:
+ tablespace_sql = ''
+ idx_name = '%s_%s' % (model._meta.db_table.replace('.', '_'), f.column)
+ output = [style.SQL_KEYWORD('CREATE INDEX') + ' ' +
+ style.SQL_TABLE(qn(idx_name)) + ' ' +
+ style.SQL_KEYWORD('ON') + ' ' +
+ style.SQL_TABLE(qn(model._meta.db_table)) + ' ' +
+ "(%s)" % style.SQL_FIELD(qn(f.column)) +
+ "%s;" % tablespace_sql]
+ else:
+ output = []
+ return output
+