Fixed upgrade function
This commit is contained in:
parent
17c82861f6
commit
16b27a7058
@ -3,25 +3,27 @@ import Dexie from "dexie";
|
|||||||
import blobToBuffer from "./helpers/blobToBuffer";
|
import blobToBuffer from "./helpers/blobToBuffer";
|
||||||
|
|
||||||
function loadVersions(db) {
|
function loadVersions(db) {
|
||||||
|
// v1.2.0
|
||||||
db.version(1).stores({
|
db.version(1).stores({
|
||||||
maps: "id, owner",
|
maps: "id, owner",
|
||||||
states: "mapId",
|
states: "mapId",
|
||||||
tokens: "id, owner",
|
tokens: "id, owner",
|
||||||
user: "key",
|
user: "key",
|
||||||
});
|
});
|
||||||
// Upgrade move from blob files to array buffers
|
// v1.2.1 - Move from blob files to array buffers
|
||||||
db.version(2)
|
db.version(2)
|
||||||
.stores({})
|
.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
|
return tx
|
||||||
.table("maps")
|
.table("maps")
|
||||||
.toCollection()
|
.toCollection()
|
||||||
.modify((map) => {
|
.modify((map) => {
|
||||||
if (map.file instanceof Blob) {
|
map.file = mapBuffers[map.id];
|
||||||
blobToBuffer(map.file).then((buffer) => {
|
|
||||||
map.file = buffer;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user