Skip to content

Version.upgrade()

David Fahlander edited this page Mar 26, 2014 · 12 revisions

Syntax

version.upgrade(upgraderFunction);

Parameters

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

Return Value

Version

Sample

var db = new Dexie("FriendsAndPetsDatabase");
db.version(2).stores({
    friends: "++id,name,birthdate,sex",
    pets: "++id,name,kind"
}).upgrade (function (trans) {
    var YEAR = 365 * 24 * 60 * 60 * 1000;
    trans.friends.each (function (friend, cursor) {
        friend.birthdate = new Date(Date.now() - (friend.age * YEAR));
        delete friend.age;
        cursor.update (friend);
    });
});
// Always keep the declarations previous versions as long as there might be users having them running.
db.version(1).stores({
    friends: "++id,name,age,sex",
    pets: "++id,name,kind"
});
db.open(); 
Clone this wiki locally