Fail with a useful error message any time a migration tries to reference a
non-existent field.
This commit is contained in:
@@ -89,11 +89,7 @@ public abstract class SchemaMigration extends Modifier
|
||||
@Override
|
||||
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
||||
super.init(tableName, marshallers);
|
||||
FieldMarshaller<?> fm = marshallers.get(_newColumnName);
|
||||
if (fm == null) {
|
||||
throw new IllegalArgumentException(
|
||||
_tableName + " does not contain '" + _newColumnName + "' field.");
|
||||
}
|
||||
FieldMarshaller<?> fm = requireMarshaller(marshallers, _newColumnName);
|
||||
_newColumnDef = fm.getColumnDefinition();
|
||||
}
|
||||
|
||||
@@ -146,8 +142,9 @@ public abstract class SchemaMigration extends Modifier
|
||||
@Override
|
||||
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
||||
super.init(tableName, marshallers);
|
||||
_columnName = marshallers.get(_fieldName).getColumnName();
|
||||
_newColumnDef = marshallers.get(_fieldName).getColumnDefinition();
|
||||
FieldMarshaller<?> marsh = requireMarshaller(marshallers, _fieldName);
|
||||
_columnName = marsh.getColumnName();
|
||||
_newColumnDef = marsh.getColumnDefinition();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,8 +182,9 @@ public abstract class SchemaMigration extends Modifier
|
||||
@Override
|
||||
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
||||
super.init(tableName, marshallers);
|
||||
_columnName = marshallers.get(_fieldName).getColumnName();
|
||||
_newColumnDef = marshallers.get(_fieldName).getColumnDefinition();
|
||||
FieldMarshaller<?> marsh = requireMarshaller(marshallers, _fieldName);
|
||||
_columnName = marsh.getColumnName();
|
||||
_newColumnDef = marsh.getColumnDefinition();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -271,6 +269,17 @@ public abstract class SchemaMigration extends Modifier
|
||||
_targetVersion = targetVersion;
|
||||
}
|
||||
|
||||
protected FieldMarshaller<?> requireMarshaller (
|
||||
Map<String, FieldMarshaller<?>> marshallers, String fieldName)
|
||||
{
|
||||
FieldMarshaller<?> marsh = marshallers.get(fieldName);
|
||||
if (marsh == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"'" + _tableName + "' does not contain field '" + fieldName + "'");
|
||||
}
|
||||
return marsh;
|
||||
}
|
||||
|
||||
protected int _targetVersion;
|
||||
protected String _tableName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user