structureChanges method
Implementation
Map<String, String> structureChanges(NUIDBEntityTracker tracker){
final matchingMap = Map<String, String>();
//Add all current fields as ADDED
for(NUIDBField t in fields()){
matchingMap[t.name] = _ADDED;
bool isNew = true;
for(NUIDBFieldTracker field in tracker.fields){
if(match(t.name, field.name)){
isNew = false;
break;
}
}
if(isNew == true && t.primaryKey == true){
//Added new primary key, recreate table
matchingMap[t.name] = _REMOVED_PRIMARY;
}
}
//Loop through the list of fields from previous version
for(NUIDBFieldTracker field in tracker.fields){
final fieldName = field.name;
bool foundField = false;
bool fieldChanged = false;
//Loop through current fields to find matches or changes
for(NUIDBField t in fields()){
if(match(t.name, fieldName)){
//Found a matching field
foundField = true;
fieldChanged = t.structureChanged(field);
break;
}
}
if(foundField){
//Found at matching field
if(fieldChanged) {
//Data type of the field changed
matchingMap[fieldName] = _UPDATED;
}
else{
//No changes for this field
matchingMap[fieldName] = _SAME;
}
}
else{
//Field removed from this entity
if(field.primaryKey == true){
matchingMap[fieldName] = _REMOVED_PRIMARY;
}
else {
matchingMap[fieldName] = _REMOVED;
}
}
}
return matchingMap;
}