markMigrationRolledBack method

Future<bool> markMigrationRolledBack({
  1. required SessionExecutor executor,
  2. required String migrationName,
  3. String? rollbackName,
})

Inserts a rollback record without executing schema statements.

Implementation

Future<bool> markMigrationRolledBack({
  required pg.SessionExecutor executor,
  required String migrationName,
  String? rollbackName,
}) async {
  await ensureHistoryTable(executor);
  final history = await loadHistory(executor);
  final activeNames = _activeMigrationNames(history);
  if (!activeNames.contains(migrationName)) {
    return false;
  }

  final targetRecord = history.lastWhere(
    (record) => record.name == migrationName,
  );
  final effectiveRollbackName =
      rollbackName ??
      '${migrationName}_resolve_rollback_${DateTime.now().toUtc().millisecondsSinceEpoch}';
  await executor.run((session) {
    return _recordHistory(
      session,
      migrationName: effectiveRollbackName,
      statementCount: 0,
      kind: PostgresqlMigrationRecordKind.rollback,
      targetName: migrationName,
      provider: providerName,
      checksum: targetRecord.checksum ?? effectiveRollbackName,
      beforeSchema:
          targetRecord.afterSchema ?? targetRecord.beforeSchema ?? '',
      afterSchema:
          targetRecord.beforeSchema ?? targetRecord.afterSchema ?? '',
      warnings: const <String>[],
      rebuildRequired: false,
    );
  });
  return true;
}