migrateFromPersistentStorage method

Future<bool> migrateFromPersistentStorage(
  1. PersistentStorage fromStorage,
  2. PersistentStorage toStorage
)

Migrate from a persistent storage to our database

Returns true if this migration took place

This is a generic migrator that copies from one storage to another, and is used by the _migrateFrom... methods

Implementation

Future<bool> migrateFromPersistentStorage(
  PersistentStorage fromStorage,
  PersistentStorage toStorage,
) async {
  bool migratedSomething = false;
  await fromStorage.initialize();
  final pausedTasks = await fromStorage.retrieveAllPausedTasks();
  if (pausedTasks.isNotEmpty) {
    await Future.wait(pausedTasks.map((e) => toStorage.storePausedTask(e)));
    migratedSomething = true;
  }
  final resumeData = await fromStorage.retrieveAllResumeData();
  if (resumeData.isNotEmpty) {
    await Future.wait(resumeData.map((e) => toStorage.storeResumeData(e)));
    migratedSomething = true;
  }
  final taskRecords = await fromStorage.retrieveAllTaskRecords();
  if (taskRecords.isNotEmpty) {
    await Future.wait(taskRecords.map((e) => toStorage.storeTaskRecord(e)));
    migratedSomething = true;
  }
  return migratedSomething;
}