Our company relies on electron-store
as the primary database for our software. However, we have encountered issues related to undefined behaviors during the initial store setup. We would greatly appreciate any help on this topic π
Our current configuration:
[email protected] -> 22.3.3
electron-store@^8.0.2 -> 8.1.0
When a migration is defined in electron-store, it is generally assumed that the store's state matches a version that is strictly less than the version specified in the migration. For instance:
migrations: {
"1.0.0": (store) => {
// The "store" version is guaranteed to be strictly less than 1.0.0
store.set("newPropertyName", store.get("oldPropertyName"));
store.delete("oldPropertyName");
// The "store" is updated to version 1.0.0 at the end of the migration
},
}
This assumption ensures that migrations can be applied sequentially to upgrade to a target version.
The current implementation initializes the store's version as "0.0.0" (hardcoded) upon its first initialization. However, the store is actually initialized with the default values of the latest version (e.g., 1.0.0), which contradicts the assumption that the store should be given to the migration in a version strictly less than 1.0.0. This discrepancy leads to undefined behaviors and potential issues.
We found a workaround to ensure that the store is always considered up to date during its first initialization by modifying the default values:
/*
Hack to make sure the store is always up to date at first init,
default behavior of electron-store being to consider the store in version '0.0.0' by default
*/
defaults: {
__internal__: {
migrations: {
version: app.getVersion(), // Our current version, e.g., '1.0.0'
},
},
}
Another possible solution is to replace the hardcoded 0.0.0 version in the conf
package source code with options.projectVersion
. This could potentially yield a similar result without modifying the default values.
We could not find any alternative method for setting the default version for migrations using the electron-store API.
Feel free to answer some of our questions if possible:
options.projectVersion
instead of the hardcoded "0.0.0" version in the conf package source code, or do you have alternative recommendations?Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too