dexie.js-web icon indicating copy to clipboard operation
dexie.js-web copied to clipboard

Perform version upgrades after importing a database

Open QuentinRoy opened this issue 3 years ago • 0 comments

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();
}

QuentinRoy avatar Jul 16 '21 18:07 QuentinRoy