How do I add an index to a previously created object store, within the upgrade needed event?
Doing this on a new object store is well documented:
request.onupgradeneeded = function(event) {
var db = event.target.result;
var objectStore = db.createObjectStore("my-store",
{ keyPath: "id" }
);
objectStore.createIndex("idx_name", "index_this", { unique: false });
};
But how can I add an index to an object store that I previously created?
request.onupgradeneeded = function(event) {
var db = event.target.result;
if (!db.objectStoreNames.contains("my-store")) {
var objectStore = db.createObjectStore("my-store",
{ keyPath: "id" }
);
}
var myStore = ?????????????;
if (!myStore.indexNames.contains("idx_name")) {
myStore.createIndex("idx_name", "index_this", { unique: false });
}
};