From 74b9e914866c4d3c2051c0f8a026092785682ce4 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Fri, 12 Mar 2021 11:19:12 +1100 Subject: [PATCH] Upgrade database to shorten fog ids --- src/database.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/database.js b/src/database.js index 31c4d69..5ed9ed2 100644 --- a/src/database.js +++ b/src/database.js @@ -1,6 +1,7 @@ // eslint-disable-next-line no-unused-vars import Dexie, { Version, DexieOptions } from "dexie"; import "dexie-observable"; +import shortid from "shortid"; import blobToBuffer from "./helpers/blobToBuffer"; import { getGridDefaultInset } from "./helpers/grid"; @@ -414,9 +415,25 @@ const versions = { 21(v) { v.stores({}); }, + // v1.8.1 - Shorten fog shape ids + 22(v) { + v.stores({}).upgrade((tx) => { + return tx + .table("states") + .toCollection() + .modify((state) => { + for (let id of Object.keys(state.fogShapes)) { + const newId = shortid.generate(); + state.fogShapes[newId] = state.fogShapes[id]; + state.fogShapes[newId].id = newId; + delete state.fogShapes[id]; + } + }); + }); + }, }; -const latestVersion = 21; +const latestVersion = 22; /** * Load versions onto a database up to a specific version number