markMigrationRolledBack method

bool markMigrationRolledBack({
  1. required Database database,
  2. required String migrationName,
  3. String? rollbackName,
})

Inserts a rollback record without executing schema statements.

Implementation

bool markMigrationRolledBack({
  required sqlite.Database database,
  required String migrationName,
  String? rollbackName,
}) {
  ensureHistoryTable(database);
  final history = loadHistory(database);
  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}';
  _recordHistory(
    database: database,
    migrationName: effectiveRollbackName,
    statementCount: 0,
    kind: SqliteMigrationRecordKind.rollback,
    provider: providerName,
    checksum: targetRecord.checksum ?? effectiveRollbackName,
    beforeSchema: targetRecord.afterSchema ?? targetRecord.beforeSchema ?? '',
    afterSchema: targetRecord.beforeSchema ?? targetRecord.afterSchema ?? '',
    warnings: const <String>[],
    rebuildRequired: false,
    targetName: migrationName,
  );
  return true;
}