Backfill constructor
Backfill(})
Prepares bounded updates over an immutable, non-null historical primary key.
Assignments must be nonempty, target writable non-key columns, and use
trusted SQL. batchSize must be positive; doneWhen must be a SELECT probe.
Implementation
Backfill(
this.table, {
required Map<String, String> set,
this.where = 'TRUE',
required this.doneWhen,
this.batchSize = 1000,
}) : set = Map.unmodifiable(set) {
SchemaSnapshot([table]);
if (batchSize < 1 ||
set.isEmpty ||
where.trim().isEmpty ||
set.entries.any(
(e) =>
e.value.trim().isEmpty ||
!table.columns.any(
(c) => c.name == e.key && !c.generated && c.computed == null,
) ||
table.primaryKey.contains(e.key),
)) {
throw ArgumentError(
'Backfill needs a positive batch size and assignments to existing non-key columns.',
);
}
if (table.primaryKey.isEmpty ||
table.columns
.where((c) => table.primaryKey.contains(c.name))
.any((c) => c.nullable || c.codec.sqlType == 'json')) {
throw const OrmException(
'MIGRATION.BACKFILL_KEY',
'Backfill requires a non-null primary key with lossless cursor storage; JSON keys are unsupported.',
);
}
if (sqlWords(doneWhen).firstOrNull != 'SELECT') {
throw const OrmException(
'MIGRATION.PROBE',
'Backfill completion must be a SELECT returning one boolean.',
);
}
}