Note the backend DB will get the given version number multiplied by 10. See Issue #59 where the reason for this behavior is described.
Return Value
Version
Sample
This sample shows how to upgrade your database. Assume your first app defines version 1 of the database like this:
var db =newDexie("FriendsAndPetsDatabase");db.version(1).stores({ friends:"++id,name,age", pets:"++id,name,kind"});db.open(); // Do some application logic on the database:db.transaction("rw",db.friends,db.pets,function () {db.friends.add({name:"David", age:40, sex:"male"});db.friends.add({name:"Ylva", age:39, sex:"female"});db.pets.add({name:"Josephina", kind:"dog"});db.friends.where("name").equalsIgnoreCase("david").each(function(friend) {console.log("Found friend: "+friend.name); });db.pets.where("kind").anyOf("dog","cat").each(function(pet) {console.log("Found dog or cat: "+pet.name); });}).catch (function (e) {console.error(e.stack || e);});
Then you realise "age" was not a good thing to store because it will change as time goes by. You want to redesign your app to store birthdate instead. Here is how version 2 of your released app would look:
var db =newDexie("FriendsAndPetsDatabase");db.version(2).stores({ friends:"++id,name,birthdate,sex", pets:"++id,name,kind"}).upgrade (tx => {varYEAR=365*24*60*60*1000;returntx.table("friends").toCollection().modify (friend => {friend.birthdate =newDate(Date.now() - (friend.age *YEAR));deletefriend.age; });});// If you are on Dexie < 3.0, also keep the declarations previous versionsdb.version(1).stores({ friends:"++id,name,age", pets:"++id,name,kind"});