2017-01-19 15:39:46 +08:00
|
|
|
class BaseDatabaseValidation:
|
2017-01-25 07:04:12 +08:00
|
|
|
"""Encapsulate backend-specific validation."""
|
2015-01-13 04:20:40 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
|
|
|
|
2016-03-19 19:15:09 +08:00
|
|
|
def check(self, **kwargs):
|
|
|
|
return []
|
|
|
|
|
2015-01-13 04:20:40 +08:00
|
|
|
def check_field(self, field, **kwargs):
|
2017-05-15 00:34:45 +08:00
|
|
|
errors = []
|
|
|
|
# Backends may implement a check_field_type() method.
|
|
|
|
if (hasattr(self, 'check_field_type') and
|
|
|
|
# Ignore any related fields.
|
|
|
|
not getattr(field, 'remote_field', None)):
|
|
|
|
# Ignore fields with unsupported features.
|
|
|
|
db_supports_all_required_features = all(
|
|
|
|
getattr(self.connection.features, feature, False)
|
|
|
|
for feature in field.model._meta.required_db_features
|
|
|
|
)
|
|
|
|
if db_supports_all_required_features:
|
|
|
|
field_type = field.db_type(self.connection)
|
|
|
|
# Ignore non-concrete fields.
|
|
|
|
if field_type is not None:
|
|
|
|
errors.extend(self.check_field_type(field, field_type))
|
|
|
|
return errors
|