structureChanges method

Map<String, String> structureChanges(
  1. NUIDatabaseTracker tracker
)

Implementation

Map<String, String> structureChanges(NUIDatabaseTracker tracker){
  final matchingMap = Map<String, String>();

  //Add all current tables as ADDED
  for(NUIDBEntityMapper t in entities()){
    matchingMap[t.entityName()] = ACTION_CREATE;
  }

  //Loop through the list of tables from previous version
  for(NUIDBEntityTracker entity in tracker.entities){
    final tableName = entity.name;
    bool foundEntity = false;
    String? action;

    //Loop through current entities to find matches or changes
    for(NUIDBEntityMapper t in entities()){
      if(match(t.entityName(), tableName)){
        //Found a matching entity
        foundEntity = true;
        action = t.migrateAction(entity);
        break;
      }
    }

    if(foundEntity){
      //Found matching entity
      matchingMap[tableName] = action ?? "";
    }
    else{
      //Entity removed from this database
      matchingMap[tableName] = ACTION_REMOVE;
    }
  }
  return matchingMap;
}