Factorized schema_editor() at BaseDatabaseWrapper level
This commit is contained in:
parent
a8f07530a7
commit
d1ca70110f
|
@ -20,13 +20,11 @@ class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures):
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(MySQLDatabaseWrapper):
|
class DatabaseWrapper(MySQLDatabaseWrapper):
|
||||||
|
SchemaEditorClass = MySQLGISSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
self.features = DatabaseFeatures(self)
|
self.features = DatabaseFeatures(self)
|
||||||
self.creation = MySQLCreation(self)
|
self.creation = MySQLCreation(self)
|
||||||
self.ops = MySQLOperations(self)
|
self.ops = MySQLOperations(self)
|
||||||
self.introspection = MySQLIntrospection(self)
|
self.introspection = MySQLIntrospection(self)
|
||||||
|
|
||||||
def schema_editor(self, *args, **kwargs):
|
|
||||||
"Returns a new instance of this backend's SchemaEditor"
|
|
||||||
return MySQLGISSchemaEditor(self, *args, **kwargs)
|
|
||||||
|
|
|
@ -15,12 +15,11 @@ class DatabaseFeatures(BaseSpatialFeatures, OracleDatabaseFeatures):
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(OracleDatabaseWrapper):
|
class DatabaseWrapper(OracleDatabaseWrapper):
|
||||||
|
SchemaEditorClass = OracleGISSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
self.features = DatabaseFeatures(self)
|
self.features = DatabaseFeatures(self)
|
||||||
self.ops = OracleOperations(self)
|
self.ops = OracleOperations(self)
|
||||||
self.creation = OracleCreation(self)
|
self.creation = OracleCreation(self)
|
||||||
self.introspection = OracleIntrospection(self)
|
self.introspection = OracleIntrospection(self)
|
||||||
|
|
||||||
def schema_editor(self, *args, **kwargs):
|
|
||||||
return OracleGISSchemaEditor(self, *args, **kwargs)
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ class DatabaseFeatures(BaseSpatialFeatures, Psycopg2DatabaseFeatures):
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(Psycopg2DatabaseWrapper):
|
class DatabaseWrapper(Psycopg2DatabaseWrapper):
|
||||||
|
SchemaEditorClass = PostGISSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
if kwargs.get('alias', '') != NO_DB_ALIAS:
|
if kwargs.get('alias', '') != NO_DB_ALIAS:
|
||||||
|
@ -23,7 +25,3 @@ class DatabaseWrapper(Psycopg2DatabaseWrapper):
|
||||||
self.creation = PostGISCreation(self)
|
self.creation = PostGISCreation(self)
|
||||||
self.ops = PostGISOperations(self)
|
self.ops = PostGISOperations(self)
|
||||||
self.introspection = PostGISIntrospection(self)
|
self.introspection = PostGISIntrospection(self)
|
||||||
|
|
||||||
def schema_editor(self, *args, **kwargs):
|
|
||||||
"Returns a new instance of this backend's SchemaEditor"
|
|
||||||
return PostGISSchemaEditor(self, *args, **kwargs)
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures):
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(SQLiteDatabaseWrapper):
|
class DatabaseWrapper(SQLiteDatabaseWrapper):
|
||||||
|
SchemaEditorClass = SpatialiteSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# Before we get too far, make sure pysqlite 2.5+ is installed.
|
# Before we get too far, make sure pysqlite 2.5+ is installed.
|
||||||
if Database.version_info < (2, 5, 0):
|
if Database.version_info < (2, 5, 0):
|
||||||
|
@ -47,10 +49,6 @@ class DatabaseWrapper(SQLiteDatabaseWrapper):
|
||||||
self.creation = SpatiaLiteCreation(self)
|
self.creation = SpatiaLiteCreation(self)
|
||||||
self.introspection = SpatiaLiteIntrospection(self)
|
self.introspection = SpatiaLiteIntrospection(self)
|
||||||
|
|
||||||
def schema_editor(self, *args, **kwargs):
|
|
||||||
"Returns a new instance of this backend's SchemaEditor"
|
|
||||||
return SpatialiteSchemaEditor(self, *args, **kwargs)
|
|
||||||
|
|
||||||
def get_new_connection(self, conn_params):
|
def get_new_connection(self, conn_params):
|
||||||
conn = super(DatabaseWrapper, self).get_new_connection(conn_params)
|
conn = super(DatabaseWrapper, self).get_new_connection(conn_params)
|
||||||
# Enabling extension loading on the SQLite connection.
|
# Enabling extension loading on the SQLite connection.
|
||||||
|
|
|
@ -37,6 +37,7 @@ class BaseDatabaseWrapper(object):
|
||||||
"""
|
"""
|
||||||
ops = None
|
ops = None
|
||||||
vendor = 'unknown'
|
vendor = 'unknown'
|
||||||
|
SchemaEditorClass = None
|
||||||
|
|
||||||
queries_limit = 9000
|
queries_limit = 9000
|
||||||
|
|
||||||
|
@ -479,8 +480,13 @@ class BaseDatabaseWrapper(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def schema_editor(self, *args, **kwargs):
|
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):
|
class BaseDatabaseFeatures(object):
|
||||||
|
|
|
@ -434,6 +434,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
}
|
}
|
||||||
|
|
||||||
Database = Database
|
Database = Database
|
||||||
|
SchemaEditorClass = DatabaseSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
@ -557,10 +558,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
table_name, column_name, bad_row[1],
|
table_name, column_name, bad_row[1],
|
||||||
referenced_table_name, referenced_column_name))
|
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):
|
def is_usable(self):
|
||||||
try:
|
try:
|
||||||
self.connection.ping()
|
self.connection.ping()
|
||||||
|
|
|
@ -593,6 +593,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
})
|
})
|
||||||
|
|
||||||
Database = Database
|
Database = Database
|
||||||
|
SchemaEditorClass = DatabaseSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*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])
|
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
|
||||||
raise
|
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
|
# Oracle doesn't support releasing savepoints. But we fake them when query
|
||||||
# logging is enabled to keep query counts consistent with other backends.
|
# logging is enabled to keep query counts consistent with other backends.
|
||||||
def _savepoint_commit(self, sid):
|
def _savepoint_commit(self, sid):
|
||||||
|
|
|
@ -91,6 +91,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
}
|
}
|
||||||
|
|
||||||
Database = Database
|
Database = Database
|
||||||
|
SchemaEditorClass = DatabaseSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
@ -198,10 +199,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def schema_editor(self, *args, **kwargs):
|
|
||||||
"Returns a new instance of this backend's SchemaEditor"
|
|
||||||
return DatabaseSchemaEditor(self, *args, **kwargs)
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def psycopg2_version(self):
|
def psycopg2_version(self):
|
||||||
version = psycopg2.__version__.split(' ', 1)[0]
|
version = psycopg2.__version__.split(' ', 1)[0]
|
||||||
|
|
|
@ -351,6 +351,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
}
|
}
|
||||||
|
|
||||||
Database = Database
|
Database = Database
|
||||||
|
SchemaEditorClass = DatabaseSchemaEditor
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
@ -489,9 +490,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
"""
|
"""
|
||||||
self.cursor().execute("BEGIN")
|
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')
|
FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue