In order to trigger a "upgradeneeded" event you need to request the database with version higher than the current version - otherwise the event won't be triggered.
function createTable(dbName, dbversion, tableName) {
var request = indexedDB.open(dbName, dbversion);
request.onupgradeneeded = function (e) {
var database = e.target.result;
var objectStore = database.createObjectStore(tableName, {
keyPath: 'id'
});
console.log("Object Store Created");
};
request.onsuccess = function (e) {
var database = e.target.result;
//code to verify that the table was created
database.objectStoreNames.contains(storeName);
database.close();
}
request.onerror = function (e) {
console.error(e.target.error.message);
}
}