[open-ils-commits] r771 - servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Feb 8 20:00:16 EST 2010
Author: gfawcett
Date: 2010-02-08 20:00:15 -0500 (Mon, 08 Feb 2010)
New Revision: 771
Added:
servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/creation.py
Modified:
servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/base.py
Log:
postgresql_with_schemas: now will properly create indexes.
Django tries to derive index names from the db_table names and column
names; but the default Postgres backend, being non-schema-aware, was
trying to use dotted names for indexes (and that's wrong).
This patch corrects the issue by overriding the index-naming code and
removing the dotted names.
Modified: servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/base.py
===================================================================
--- servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/base.py 2010-02-08 19:19:42 UTC (rev 770)
+++ servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/base.py 2010-02-09 01:00:15 UTC (rev 771)
@@ -8,11 +8,13 @@
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):
Added: servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/creation.py
===================================================================
--- servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/creation.py (rev 0)
+++ servres/branches/eg-schema-experiment/conifer/evergreen/backends/postgresql_with_schemas/creation.py 2010-02-09 01:00:15 UTC (rev 771)
@@ -0,0 +1,28 @@
+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
+
More information about the open-ils-commits
mailing list