question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't do async data migrations in the sync upgrade function

See original GitHub issue

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:

upgrade(db, oldVersion, newVersion, transaction) {
           const blogPosts = await db.getAll('blogPosts') // Oh, no! We can't await anything here
           db.deleteObjectStore('blogPosts')
           // Re-create the store with the new schema
           // Remap and save all the items
      }

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?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lkarabegcommented, Sep 2, 2022

That’s amazing, thanks for your help!

0reactions
jakearchibaldcommented, Sep 2, 2022

No problem! The lifetime of IDB transitions is pretty weird, unfortunately I can’t really change that 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Question]Can i use async db driver to serve db changes? #805
Hi guys! I'm newbie with alembic and wanted clarify one thing. As i understood based on docs, alembic uses sync database driver(for example, ......
Read more >
Sequelize.js: how to use migrations and sync - Stack Overflow
Generating the "first migration". In your case, the most reliable way is to do it almost manually. I would suggest to use sequelize-cli...
Read more >
Update on Async Rendering – React Blog
The recommended upgrade path for most use cases is to move data-fetching into componentDidMount :
Read more >
How to automate database migrations in MongoDB
Introduction · Write a script that will take care of upgrading the schema as well as downgrading it to previous versions · Update...
Read more >
From Sync to Async - WebdriverIO
Due to changes in V8 the WebdriverIO team announced to deprecate synchronous command execution by April 2023. The team has been working hard...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found