run method

Future<void> run(
  1. T schema,
  2. Future<void> invokeMigrations(
    1. Migration,
    2. Object?
    )
)

///////////////////////////////////////////////////////////////////////// Runs the migrations within the schema and protects for failures.

Implementation

/// Runs the migrations within the schema and protects for failures.
Future<void> run(T schema,
    Future<void> Function(Migration, Object?) invokeMigrations) async {
  createDbBackup(schema);
  try {
    for (var migration in schema.migrations) {
      if (migration.migrationState == MigrationState.hasNotRan) {
        await invokeMigrations(migration, schema.context);
      }
    }
  } on Exception catch (e1) {
    try {
      restoreDbFromBackup(schema);
      dropDbBackup(schema);
      rethrow;
    } on Exception catch (e2) {
      if (e1 != e2) {
        try {
          migrationFailedAndRestoreFailedProtocol(schema);
          throw e1.chain(e2);
        } on UnimplementedError {
          throw e1.chain(e2).chain(MigrationException(
              "Migration failed and restore failed without an implementation of a protocol for this edge case."));
        }
      } else {
        rethrow;
      }
    }
  }
  dropDbBackup(schema);
}