generate static method

String generate(
  1. List<MigrationCommand> commands,
  2. int version
)

Implementation

static String generate(List<MigrationCommand> commands, int version) {
  final upCommands = commands.map((m) => m.forGenerator);
  final downCommands = commands.map((m) => m.down?.forGenerator).toList().whereType<String>();

  return '''
// GENERATED CODE EDIT WITH CAUTION
// THIS FILE **WILL NOT** BE REGENERATED
// This file should be version controlled and can be manually edited.
part of 'schema.g.dart';

// While migrations are intelligently created, the difference between some commands, such as
// DropTable vs. RenameTable, cannot be determined. For this reason, please review migrations after
// they are created to ensure the correct inference was made.

// The migration version must **always** mirror the file name

const List<MigrationCommand> _migration_${version}_up = [
${upCommands.join(',\n  ')}
];

const List<MigrationCommand> _migration_${version}_down = [
${downCommands.join(',\n  ')}
];

//
// DO NOT EDIT BELOW THIS LINE
//

@Migratable(
version: '$version',
up: _migration_${version}_up,
down: _migration_${version}_down,
)
class Migration$version extends Migration {
const Migration$version()
  : super(
      version: $version,
      up: _migration_${version}_up,
      down: _migration_${version}_down,
    );
}
''';
}