When upgrading database I want to move some data from one store to another. But I'm not able to do like this:
import { openDB } from 'idb';
const testVersion = 2;
const db = await openDB('Profile', testVersion, {
upgrade: async (db, oldVersion, newVersion) => {
if (newVersion === 1) {
db.createObjectStore(username);
} else if (newVersion === 2) {
db.createObjectStore('profileImage');
try {
const storedInPreviousVersion = await db.get(
username,
'profileImage'
);
await db.put('profileImage', storedInPreviousVersion, username);
db.deleteObjectStore(username);
} catch (e) {
console.error('Did not find old store', e);
}
}
}
});
It seems to be impossible to get a value within an upgrade. Is there any way around this limitation?