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
|
@Override
|
||||||
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
||||||
super.init(tableName, marshallers);
|
super.init(tableName, marshallers);
|
||||||
FieldMarshaller<?> fm = marshallers.get(_newColumnName);
|
FieldMarshaller<?> fm = requireMarshaller(marshallers, _newColumnName);
|
||||||
if (fm == null) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
_tableName + " does not contain '" + _newColumnName + "' field.");
|
|
||||||
}
|
|
||||||
_newColumnDef = fm.getColumnDefinition();
|
_newColumnDef = fm.getColumnDefinition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,8 +142,9 @@ public abstract class SchemaMigration extends Modifier
|
|||||||
@Override
|
@Override
|
||||||
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
||||||
super.init(tableName, marshallers);
|
super.init(tableName, marshallers);
|
||||||
_columnName = marshallers.get(_fieldName).getColumnName();
|
FieldMarshaller<?> marsh = requireMarshaller(marshallers, _fieldName);
|
||||||
_newColumnDef = marshallers.get(_fieldName).getColumnDefinition();
|
_columnName = marsh.getColumnName();
|
||||||
|
_newColumnDef = marsh.getColumnDefinition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,8 +182,9 @@ public abstract class SchemaMigration extends Modifier
|
|||||||
@Override
|
@Override
|
||||||
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
public void init (String tableName, Map<String, FieldMarshaller<?>> marshallers) {
|
||||||
super.init(tableName, marshallers);
|
super.init(tableName, marshallers);
|
||||||
_columnName = marshallers.get(_fieldName).getColumnName();
|
FieldMarshaller<?> marsh = requireMarshaller(marshallers, _fieldName);
|
||||||
_newColumnDef = marshallers.get(_fieldName).getColumnDefinition();
|
_columnName = marsh.getColumnName();
|
||||||
|
_newColumnDef = marsh.getColumnDefinition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -271,6 +269,17 @@ public abstract class SchemaMigration extends Modifier
|
|||||||
_targetVersion = targetVersion;
|
_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 int _targetVersion;
|
||||||
protected String _tableName;
|
protected String _tableName;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user