If the db version is too old, skip the upgrade and clear the tables? #2214
-
|
Is it possible to force the user to use a fresh, empty database if their database version is too outdated and no longer supported? For example, my database version is currently 100, and it only supports upgrading starting from version 91+, so if the user’s version is 90, I want to force them to use a fresh database. Most of the errors my users have is that they come back to my site after a few months and I have already moved on and removed some of the upgrade code. My problem is probably that I’m unsure where to place the logic for this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
If you would be okay with clearing all data in all tables for any user on version before 91, you can do like this: db.version(91).upgrade(tx => {
for (const table of tx.storeNames) {
tx.table(table).clear();
}
});Anyone on version 90 or below will hit this code and get all their data cleared. This is not exactly the same as db.delete() but in practice, it's the same effect. If hard database delete is important for you, the following would also work but feels a bit more hacky: db.version(91).upgrade(() => {
db.on('ready', () => {
db.delete().then(()=>db.open());
}
});That said, I've seen this requirement before and I think a built-in solution into dexie would be nice. Maybe: db.version(91).upgrade({
recreate: true
});Thoughs are welcome! |
Beta Was this translation helpful? Give feedback.
If you would be okay with clearing all data in all tables for any user on version before 91, you can do like this:
Anyone on version 90 or below will hit this code and get all their data cleared. This is not exactly the same as db.delete() but in practice, it's the same effect.
If hard database delete is important for you, the following would also work but feels a bit more hacky:
That said, I've seen this requirement before and I think a built-in solution into dexie would be n…