rollback method
Implementation
@override
Future rollback() async {
await _init();
var r = await connection.query('SELECT MAX(batch) from migrations;');
var rTmp = r.toList();
var curBatch = (rTmp[0][0] ?? 0) as int;
r = await connection
.query('SELECT path from migrations WHERE batch = $curBatch;');
var existing = r.expand((x) => x).cast<String>();
var toRun = <String>[];
migrations.forEach((k, v) {
if (existing.contains(k)) toRun.add(k);
});
if (toRun.isNotEmpty) {
for (var k in toRun.reversed) {
var migration = migrations[k]!;
var schema = MysqlSchema();
migration.down(schema);
_log.info('Removed "$k" from "migrations" table.');
await schema.run(connection).then((_) {
return connection
.query('DELETE FROM migrations WHERE path = \'$k\';');
});
}
} else {
_log.warning('Nothing to remove from "migrations" table.');
}
}