X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FgameStorage.js;h=514448b080eaf261ee6970f53d5a13b62b18145f;hb=bee36510477b04dee500a9a624584544b9c8bdb2;hp=fc179f19b8bd865b54a914e1f02bed774c7c3cb2;hpb=8f16069a55fdbbb92f62eb385daf776bef4fc7fd;p=vchess.git diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index fc179f19..514448b0 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -34,11 +34,18 @@ function dbOperation(callback) { DBOpenRequest.onupgradeneeded = function(event) { let db = event.target.result; - let objectStore = db.createObjectStore("games", { keyPath: "id" }); - // To sarch games by score (useful for running games) - objectStore.createIndex("score", "score", { unique: false }); - // To search by date intervals. Two games cannot start at the same time - objectStore.createIndex("created", "created", { unique: true }); + let upgradeTransaction = event.target.transaction; + let objectStore = undefined; + if (!db.objectStoreNames.contains("games")) + objectStore = db.createObjectStore("games", { keyPath: "id" }); + else + objectStore = upgradeTransaction.objectStore("games"); + if (!objectStore.indexNames.contains("score")) + // To sarch games by score (useful for running games) + objectStore.createIndex("score", "score", { unique: false }); + if (!objectStore.indexNames.contains("created")) + // To search by date intervals. Two games cannot start at the same time + objectStore.createIndex("created", "created", { unique: true }); }; }