From 16b27a7058bfbb39d4384d8f5d3317ba67284024 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Sun, 3 May 2020 22:12:39 +1000 Subject: [PATCH] Fixed upgrade function --- src/database.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/database.js b/src/database.js index b3f1f08..71851cb 100644 --- a/src/database.js +++ b/src/database.js @@ -3,25 +3,27 @@ import Dexie from "dexie"; import blobToBuffer from "./helpers/blobToBuffer"; function loadVersions(db) { + // v1.2.0 db.version(1).stores({ maps: "id, owner", states: "mapId", tokens: "id, owner", user: "key", }); - // Upgrade move from blob files to array buffers + // v1.2.1 - Move from blob files to array buffers db.version(2) .stores({}) - .upgrade((tx) => { + .upgrade(async (tx) => { + const maps = await Dexie.waitFor(tx.table("maps").toArray()); + let mapBuffers = {}; + for (let map of maps) { + mapBuffers[map.id] = await Dexie.waitFor(blobToBuffer(map.file)); + } return tx .table("maps") .toCollection() .modify((map) => { - if (map.file instanceof Blob) { - blobToBuffer(map.file).then((buffer) => { - map.file = buffer; - }); - } + map.file = mapBuffers[map.id]; }); }); }