I'm trying to forcefully update a database in IndexedDB by sending an open request with the current database's version number incremented by one with:
var openRequest = indexedDB.open("db-name", dbVariable.version + 1);
However the onupgradeneeded
event is never triggered and the openRequest
stays in the pending
state indefinitely.
What am I doing wrong?
Is there another way to forcefully update a database in IndexedDB?
EDIT
Say I have a function connect2db
which takes variable version
:
function connect2db(version) {
var openRequest = indexedDB.open("database-name", version);
openRequest.onsuccess = function(e) {
databaseVariable = e.target.result;
}
openRequest.onupgradeneeded = function(e) {
databaseVariable = e.target.result;
// Do schema update...
}
}
And I have another circumstance where I'd like to update the database schema:
connect2db(databaseVariable.version + 1);
Assume darabaseVariable
already exists and points to a database
When I've tried running code in this format, the onupgradeneeded
event is never triggered. What could be going wrong?