From 8d19b801538e2be842ebe2d03ca464f72bb95edb Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 23 Sep 2022 21:00:51 +0200 Subject: wallet-core: backwards compatibility for bankAccounts store, naming conventions --- packages/taler-wallet-core/src/db-utils.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'packages/taler-wallet-core/src/db-utils.ts') diff --git a/packages/taler-wallet-core/src/db-utils.ts b/packages/taler-wallet-core/src/db-utils.ts index 2cb1b12fe..88960e6b1 100644 --- a/packages/taler-wallet-core/src/db-utils.ts +++ b/packages/taler-wallet-core/src/db-utils.ts @@ -70,7 +70,31 @@ function upgradeFromStoreMap( return; } logger.info(`upgrading database from ${oldVersion} to ${newVersion}`); - throw Error("upgrade not supported"); + for (const n in storeMap) { + const swi: StoreWithIndexes, any> = storeMap[ + n + ]; + const storeDesc: StoreDescriptor = swi.store; + const storeAddedVersion = storeDesc.versionAdded ?? 0; + if (storeAddedVersion <= oldVersion) { + continue; + } + const s = db.createObjectStore(swi.storeName, { + autoIncrement: storeDesc.autoIncrement, + keyPath: storeDesc.keyPath, + }); + for (const indexName in swi.indexMap as any) { + const indexDesc: IndexDescriptor = swi.indexMap[indexName]; + const indexAddedVersion = indexDesc.versionAdded ?? 0; + if (indexAddedVersion <= oldVersion) { + continue; + } + s.createIndex(indexDesc.name, indexDesc.keyPath, { + multiEntry: indexDesc.multiEntry, + unique: indexDesc.unique, + }); + } + } } function promiseFromTransaction(transaction: IDBTransaction): Promise { -- cgit v1.2.3