Version.upgrade()

Syntax

version.upgrade (upgraderFunction);

Parameters

upgraderFunction Callback function with signature function(transaction){} where transaction is an instance of Transaction

Return Value

Version

Sample

var db = new Dexie("FriendsAndPetsDatabase");

db.version(1).stores({
    friends: "++id,name,age,sex"
});

db.version(2).stores({
    friends: "++id,name,birthdate,sex"
}).upgrade (function (trans) {
    var YEAR = 365 * 24 * 60 * 60 * 1000;
    trans.friends.toCollection().modify (function (friend) {
        friend.birthdate = new Date(Date.now() - (friend.age * YEAR));
        delete friend.age;
    });
});

db.open(); 

See Also

Database Versioning

Table of Contents