buildMigrationSqlScript function
Builds the canonical SQL script for a migration plan.
Implementation
String buildMigrationSqlScript(PlannedMigration plan) {
if (plan.requiresRebuild) {
return '-- Schema rebuild required to apply this migration safely.\n';
}
if (plan.statements.isEmpty) {
if (containsManualMigrationWarnings(plan.warnings)) {
return '''-- Manual migration required.
-- This schema change could not be converted into executable SQL automatically.
-- Apply the required SQL changes manually, then mark the migration as applied with migrate resolve.
''';
}
return '-- No schema changes required.\n';
}
return '${plan.statements.join(';\n')};\n';
}