Closed lkarabeg closed 2 years ago
Put async
before upgrade
?
I assume upgrade is not awaited, so if there are multiple migrations and it takes a bit of time, then the database object could be put to use in application code while the store is in some intermediate state.
It follows usual transaction rules https://github.com/jakearchibald/idb#transaction-lifetime
Sorry if I'm missing your point, but I want to be sure the upgrade is complete when the openDB promise resolves.
const db = await openDB<AppDb>("appData", currentVersion, {
async upgrade(db, oldVersion, newVersion, transaction) {
// Do a ton of stuff
},
...
})
const allItems = await db.getAll('things') // Is the upgrade certainly done by now?
Yep, that's how it works
That's amazing, thanks for your help!
No problem! The lifetime of IDB transitions is pretty weird, unfortunately I can't really change that 😄
It seems that all methods of retrieving items from a store return a promise, which can't be awaited in the upgrade function.
Let's say my blogPost type has changed. The ID used to be a number, but is now a string, Then it would be nice to be able to do something like this:
It would be nice if the upgrade function was async so that this type of thing can be done.
Is there any workaround for this?