generate method
Generates SQL DDL statements from a list of diff operations.
Overridable so a dialect can validate ACROSS operations (e.g. SQLite rejects a rebuild whose dependent table is itself altered in the same run), overrides should still delegate here for the per-operation work.
Implementation
@override
String generate(List<DiffOperation> operations) {
final altered = {
for (final op in operations)
if (op case final AlterTable alter) alter.tableName,
};
for (final op in operations) {
if (op case final AlterTable alter when _needsRebuild(alter)) {
for (final dependent in alter.referencedBy) {
if (altered.contains(dependent.table.name)) {
throw UnsupportedError(
'''
Rebuilding "${alter.tableName}" must recreate "${dependent.table.name}", which is itself altered in this migration. Split the two changes into separate migrations.''',
);
}
}
}
}
return super.generate(operations);
}