dexie.js-web
dexie.js-web copied to clipboard
Perform version upgrades after importing a database
Feature Request
Available Version.upgrade
could be run when using importInto
.
Use Case
I am using Dexie export to let my users locally save and share their work. After a model upgrade, a run into the issue of version incompatibility.
Dexie has a very nice version upgrade feature that I have been happily leveraging when creating my database from indexedDB, unfortunately it won't work when using importInto
.
Current Workaround
async function import(file: File) {
// Completely delete the current data base. Import should overwrite
// everything anyway.
await db.delete();
// Export file may be outdated. For this reason, we cannot use
// importInto. Instead, we import the new database in a new (default)
// Dexie instance to save the potentially outdated data in instance db.
let newDb = await importDB(file);
await newDb.close();
// Recreate the database using our custom database class. This
// will trigger the version upgrade if needed.
db = new Database();
await db.open();
}