replay method
Replay entry under its existing commitId WITHOUT firing
change-event listeners. Used by the persistence migrator to
copy commit-log content from one backend to another while
preserving sync identity. Idempotent on
(commitId, atKey, operation).
Implementation
@override
Future<void> replay(CommitEntry entry) async {
if (entry.commitId == null) {
throw DataStoreException('replay requires a non-null commitId');
}
_db.runInTransaction(() {
_db.raw.execute(
'INSERT INTO commit_log (atkey, commit_id, operation, op_time) '
'VALUES (?, ?, ?, ?) '
'ON CONFLICT(atkey) DO UPDATE SET '
'commit_id = excluded.commit_id, operation = excluded.operation, '
'op_time = excluded.op_time;',
[
entry.atKey,
entry.commitId,
entry.operation.name,
entry.opTime?.toUtc().millisecondsSinceEpoch,
],
);
// Keep the allocator ahead of every replayed id so subsequent live
// commits stay monotonic and never collide with a migrated id.
_db.raw.execute(
"UPDATE counters SET value = MAX(value, ?) WHERE name = 'last_commit_id';",
[entry.commitId]);
});
}