sindresorhus / electron-store

Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc
MIT License
4.57k stars 148 forks source link

Can't get the right version when use migrations. #247

Open Penggeor opened 1 year ago

Penggeor commented 1 year ago

I am encountering the same in #108 . The __internal__.migrations.version always is 8.1.01 from electron-store instead of my project. I have to resort to the workaround by add projectVersion to get the right version:

const store = new Store({
  projectVersion: app.getVersion(), 
  schema,
  beforeEachMigration: (store, context) => {
    console.log(
      `[main-config] migrate from ${context.fromVersion} → ${context.toVersion}`,
    )
  },
  migrations: {
    '<1.2.2': (store) => {
      console.log('[<1.2.2]')
    },
    '>=1.2.2': (store) => {
      // ...
    },
    '>=1.2.3': (store) => {
      console.log('[>=1.2.3]')
    },
  },
})
sindresorhus commented 1 year ago

Try logging what appVersion is here: https://github.com/sindresorhus/electron-store/blob/e53ceefee7138b2166a222e0f339f5d5fd0035c6/index.js#L57

And make sure you are calling initRenderer() if required. See readme.

Penggeor commented 1 year ago

I found another problem, the config.json stores in ~/Library/Preferences/electron-store-nodejs/config.json @sindresorhus