Currently when we check the status of candidates we get an object from the database.
The database query functions initialize the model and add any new keys even if they are empty (undefined/empty string/null).
Empty keys (e.g. empty string) can also be the desired state that needs to be commited in case a user updates a value like that.
e.g.
Previous version of object:
{
"id": "1",
}
New version of object:
{
"id": "1",
"newProp": undefined
}
This should not show up in changes that need to be commited.
Approaches Tested:
Use the VCS to compare against the previous version of an object.
If the previous version doesn't have a key and the new version contains an empty value for that key then it won't appear as a changed property in the status diff.
Only update properties of objects in the database if the value of a key is not empty for keys that have a default undefined value
Only handle this for new keys. New keys can be defined as optional.
Comparison between the two approaches:
VCS (Compare against previous version)
DB (only update keys that are optional if they have a value)
Models (New keys should be optional and default to undefined)
Doesn't rely on undefined values on the initial model
Relies on undefined values on the initial model
Relies on new keys defaulting to undefined
Works for any kind of diff that happens between two versions of an object. If the previous version doesn't contain a key and the new version has an empty value* there will not be any changes
Only works for keys that are specified as undefined in the initial model and only for when we call the database.update method.
Works for all objects
Requires getting the previous version of the document using a specific method for VCS (different between Insomnia Sync and Git Sync)
Works with all types of VCS since it only relies on DB models
Works for all types of VCS
TBD how this works with a previous version of the app pulling and pushing changes
TBD how this works with a previous version of the app pulling and pushing changes
✅ Tested with previous versions
✅ After discussion with the team we decided to go with the last approach: Models (new keys should be optional and default to undefined)
Highlights:
Problem:
e.g. Previous version of object:
New version of object:
This should not show up in changes that need to be commited.
Approaches Tested:
Use the VCS to compare against the previous version of an object.
Only update properties of objects in the database if the value of a key is not empty for keys that have a default undefined value
Only handle this for new keys. New keys can be defined as optional.
Comparison between the two approaches:
✅ After discussion with the team we decided to go with the last approach: Models (new keys should be optional and default to undefined)