summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-09-25 19:59:03 +0200
committerClaude Paroz <claude@2xlibre.net>2014-09-26 08:50:16 +0200
commitd1ca70110f49f0be90206c8da516ac16aebc8c75 (patch)
tree9aa9853a39d4e81ad4ae651df02d1d924bcd6f7a /django/db
parenta8f07530a74839d20f1f2fb2cc7f5b8ef2215782 (diff)
Factorized schema_editor() at BaseDatabaseWrapper level
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/__init__.py10
-rw-r--r--django/db/backends/mysql/base.py5
-rw-r--r--django/db/backends/oracle/base.py5
-rw-r--r--django/db/backends/postgresql_psycopg2/base.py5
-rw-r--r--django/db/backends/sqlite3/base.py4
5 files changed, 12 insertions, 17 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 1f0e7b255c..9873d9cba6 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -37,6 +37,7 @@ class BaseDatabaseWrapper(object):
"""
ops = None
vendor = 'unknown'
+ SchemaEditorClass = None
queries_limit = 9000
@@ -479,8 +480,13 @@ class BaseDatabaseWrapper(object):
)
def schema_editor(self, *args, **kwargs):
- "Returns a new instance of this backend's SchemaEditor"
- raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a schema_editor() method')
+ """
+ Returns a new instance of this backend's SchemaEditor.
+ """
+ if self.SchemaEditorClass is None:
+ raise NotImplementedError(
+ 'The SchemaEditorClass attribute of this database wrapper is still None')
+ return self.SchemaEditorClass(self, *args, **kwargs)
class BaseDatabaseFeatures(object):
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index aefe4262e6..7223780081 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -434,6 +434,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
}
Database = Database
+ SchemaEditorClass = DatabaseSchemaEditor
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
@@ -557,10 +558,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
table_name, column_name, bad_row[1],
referenced_table_name, referenced_column_name))
- def schema_editor(self, *args, **kwargs):
- "Returns a new instance of this backend's SchemaEditor"
- return DatabaseSchemaEditor(self, *args, **kwargs)
-
def is_usable(self):
try:
self.connection.ping()
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index e48c82f0d8..083ba18daa 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -593,6 +593,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
})
Database = Database
+ SchemaEditorClass = DatabaseSchemaEditor
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
@@ -693,10 +694,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
raise
- def schema_editor(self, *args, **kwargs):
- "Returns a new instance of this backend's SchemaEditor"
- return DatabaseSchemaEditor(self, *args, **kwargs)
-
# Oracle doesn't support releasing savepoints. But we fake them when query
# logging is enabled to keep query counts consistent with other backends.
def _savepoint_commit(self, sid):
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index 975eee4df2..7de52d7592 100644
--- a/django/db/backends/postgresql_psycopg2/base.py
+++ b/django/db/backends/postgresql_psycopg2/base.py
@@ -91,6 +91,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
}
Database = Database
+ SchemaEditorClass = DatabaseSchemaEditor
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
@@ -198,10 +199,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
else:
return True
- def schema_editor(self, *args, **kwargs):
- "Returns a new instance of this backend's SchemaEditor"
- return DatabaseSchemaEditor(self, *args, **kwargs)
-
@cached_property
def psycopg2_version(self):
version = psycopg2.__version__.split(' ', 1)[0]
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 0e1070e6e5..349fae0253 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -351,6 +351,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
}
Database = Database
+ SchemaEditorClass = DatabaseSchemaEditor
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
@@ -489,9 +490,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
"""
self.cursor().execute("BEGIN")
- def schema_editor(self, *args, **kwargs):
- "Returns a new instance of this backend's SchemaEditor"
- return DatabaseSchemaEditor(self, *args, **kwargs)
FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')