azu / kvs

Lightweight key-value storage library for Browser, Node.js, and In-Memory.
MIT License
183 stars 6 forks source link

Version stays at 1 #30

Closed Kalabasa closed 2 years ago

Kalabasa commented 2 years ago

Version is always 1, no matter what you put in. It also causes the upgrade function to be called every time.

kvsEnvStorage({
  name: 'data',
  version: 2,
  upgrade: (_, old, new) => console.log('I am always called', old, new), // I am always called 1 2
})
azu commented 2 years ago

Can you provide reproduce example?

browser:

(async () => {
  const { kvsEnvStorage } = await import("https://cdn.skypack.dev/@kvs/env@2.1.2");
  const storage = await kvsEnvStorage({
    name: "database-name",
    version: 2,
    async upgrade({ kvs, oldVersion, newVersion }) {
      console.log({
        oldVersion, // 0
        newVersion // 2
      });
    }
  });
})();

node:

https://replit.com/@azu2/kvs-env-new-version?v=1#index.js

Kalabasa commented 2 years ago

It is reproducible it in your node replit example. Check ~/kvs-env-new-version/.cache/kvs-node-localstorage/database-name.__.__kvs_version__. Version is always 1, regardless of the version in the app.

Kalabasa commented 2 years ago

Another example: https://replit.com/@Kalabasa-/kvs-env-new-version#index.js

azu commented 2 years ago

https://github.com/azu/kvs/blob/7b4953ee016bae296d6f8ad5847803de06322823/packages/storage/src/storage.ts#L120-L131 Maybe, we need to write version to storage.

TODO

azu commented 2 years ago

Fixed in https://github.com/azu/kvs/releases/tag/v2.1.3