evolve method
Adds or removes columns. Must be idempotent: a crash after it and before the checkpoint delivers it again.
Implementation
@override
Future<void> evolve(DVCaptureSchemaChange change) async {
for (final String field in change.columns) {
_checkField(field);
}
if (change.phase == DVCaptureSchemaPhase.expand) {
// Added now when the type is declared; otherwise the first value
// decides, and the field is added with it.
await _ensureModel(change.model, <String, DVFieldType>{
if (fieldType != null)
for (final String field in change.columns)
field: fieldType!(change.model, field),
});
return;
}
// A store has no column to drop, so what the source no longer declares
// is removed from every copy instead: its values, which is what a
// dropped column took with it. A field that became sensitive leaves the
// destination this way too.
await _ensureModel(change.model, <String, DVFieldType>{
for (final String field in change.columns)
if (!(_fields[change.model]?.containsKey(field) ?? false))
field: DVFieldType.text,
});
for (final String field in change.columns) {
await _records.update(
change.model,
<String, Object?>{field: null},
where: DVFilter.isNotNull(field),
);
}
}