Add database migration

// FREEBIE
This commit is contained in:
lilia 2017-05-24 13:14:56 -07:00 committed by Scott Nonnenberg
parent 5a3610c8e0
commit 9f4a657e8a
1 changed files with 38 additions and 0 deletions

View File

@ -217,6 +217,44 @@
});
next();
}
},
{
version: "13.0",
migrate: function(transaction, next) {
console.log('migration 13.0');
console.log('Adding fields to identity keys');
var identityKeys = transaction.objectStore('identityKeys');
var request = identityKeys.openCursor();
var promises = [];
request.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
var attributes = cursor.value;
attributes.timestamp = 0;
attributes.firstUse = false;
attributes.blockingApproval = true;
attributes.nonblockingApproval = false;
attributes.seen = 0;
promises.push(new Promise(function(resolve, reject) {
var putRequest = identityKeys.put(attributes, attributes.id);
putRequest.onsuccess = resolve;
putRequest.onerror = function(e) {
console.log(e);
reject(e);
};
}));
cursor.continue();
} else {
// no more results
Promise.all(promises).then(function() {
next();
});
}
};
request.onerror = function(event) {
console.log(event);
};
}
}
];
}());