splitTidbAdditiveSchemaMigrations function
Splits generated additive schema into independently deployable table jobs.
Implementation
List<String> splitTidbAdditiveSchemaMigrations(String source) {
final marker = RegExp(
r"CREATE DATABASE IF NOT EXISTS `([A-Za-z0-9_]+)`;\s*"
r"USE `\1`;\s*",
);
final matches = marker.allMatches(source).toList();
return [
for (var index = 0; index < matches.length; index++)
"CREATE DATABASE IF NOT EXISTS `${matches[index].group(1)}`;\n"
"USE `${matches[index].group(1)}`;\n"
"${source.substring(
matches[index].end,
index + 1 < matches.length
? matches[index + 1].start
: source.length,
).trim()}",
];
}