Skip to content

Commit 26df5b3

Browse files
committed
Add beforeEachMigration option
1 parent e78308b commit 26df5b3

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"save"
3535
],
3636
"dependencies": {
37-
"conf": "^10.1.2",
38-
"type-fest": "^2.12.2"
37+
"conf": "^10.2.0",
38+
"type-fest": "^2.17.0"
3939
},
4040
"devDependencies": {
4141
"ava": "^2.4.0",

readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,52 @@ const store = new Store({
158158
});
159159
```
160160

161+
### beforeEachMigration
162+
163+
Type: `Function`\
164+
Default: `undefined`
165+
166+
The given callback function will be called before each migration step.
167+
168+
The function receives the store as the first argument and a context object as the second argument with the following properties:
169+
170+
- `fromVersion` - The version the migration step is being migrated from.
171+
- `toVersion` - The version the migration step is being migrated to.
172+
- `finalVersion` - The final version after all the migrations are applied.
173+
- `versions` - All the versions with a migration step.
174+
175+
This can be useful for logging purposes, preparing migration data, etc.
176+
177+
Example:
178+
179+
```js
180+
const Store = require('electron-store');
181+
182+
console.log = someLogger.log;
183+
184+
const mainConfig = new Store({
185+
beforeEachMigration: (store, context) => {
186+
console.log(`[main-config] migrate from ${context.fromVersion}${context.toVersion}`);
187+
},
188+
migrations: {
189+
'0.4.0': store => {
190+
store.set('debugPhase', true);
191+
}
192+
}
193+
});
194+
195+
const secondConfig = new Store({
196+
beforeEachMigration: (store, context) => {
197+
console.log(`[second-config] migrate from ${context.fromVersion}${context.toVersion}`);
198+
},
199+
migrations: {
200+
'1.0.1': store => {
201+
store.set('debugPhase', true);
202+
}
203+
}
204+
});
205+
```
206+
161207
#### name
162208

163209
Type: `string`\

0 commit comments

Comments
 (0)