javascript - IndexedDB handle data migration onupgradeneeded -


i'm developing offline-webapplication indexeddb. thought lot data migration in case of version change.

for example, had 3 objectstores in db version 3. noticed, should have specific index @ 3 objectstores. not possible add index afterwards existing objectstore, without losing data.

what solution handle data migration in "onupgradeneeded"-event?

no need kill storeobject update :

request.onupgradeneeded = function(evt) {          var database = evt.target.result;         var txn = evt.target.transaction;         //////////         var storecreateindex = function (objectstore, name, options) {             if (!objectstore.indexnames.contains(name)) {                 objectstore.createindex(name, name, options);             }         }         //////////         var catalogitem, mangaitem, chapteritem, artworkitem;         if (evt.newversion != evt.oldversion) {             // exiting objectstore             catalogitem = txn.objectstore('catalogitem');             mangaitem = txn.objectstore('mangaitem');             chapteritem = txn.objectstore('chapteritem');             artworkitem = txn.objectstore('artworklist');         } else {             // fist creation of database objectstore             catalogitem = database.db.createobjectstore("catalogitem", { keypath: "key" });             mangaitem = database.db.createobjectstore("mangaitem", { keypath: "key" });             chapteritem = database.db.createobjectstore("chapteritem", { keypath: "key" });             artworkitem = database.db.createobjectstore("artworklist", { keypath: "key" });         }         //////////         storecreateindex(catalogitem, "popularity", { unique: false });         storecreateindex(catalogitem, "author", { unique: false });         storecreateindex(catalogitem, "status", { unique: false });         storecreateindex(catalogitem, "isfavorite", { unique: false });         storecreateindex(chapteritem, "isbookmarked", { unique: false });         storecreateindex(chapteritem, "isdownloaded", { unique: false }); } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -