From 85c5c6d7c7304801fd223abea724fe67a56ff5fa Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 20 Feb 2023 15:07:30 +0100 Subject: wallet-core: fix DB migration logic when only an index is added --- packages/taler-wallet-core/src/db.ts | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'packages') diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 7e1906351..a23ba0f76 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -118,7 +118,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName"; * backwards-compatible way or object stores and indices * are added. */ -export const WALLET_DB_MINOR_VERSION = 4; +export const WALLET_DB_MINOR_VERSION = 5; /** * Ranges for operation status fields. @@ -2291,7 +2291,7 @@ export const WalletStoresV1 = { "byExchangeAndContractPriv", ["exchangeBaseUrl", "contractPriv"], { - versionAdded: 4, + versionAdded: 5, unique: true, }, ), @@ -2299,7 +2299,7 @@ export const WalletStoresV1 = { "byWithdrawalGroupId", "withdrawalGroupId", { - versionAdded: 4, + versionAdded: 5, }, ), byStatus: describeIndex("byStatus", "status"), @@ -2319,7 +2319,7 @@ export const WalletStoresV1 = { "byExchangeAndContractPriv", ["exchangeBaseUrl", "contractPriv"], { - versionAdded: 4, + versionAdded: 5, unique: true, }, ), @@ -2337,7 +2337,7 @@ export const WalletStoresV1 = { "byWithdrawalGroupId", "withdrawalGroupId", { - versionAdded: 4, + versionAdded: 5, }, ), }, @@ -2663,28 +2663,28 @@ function upgradeFromStoreMap( ]; const storeDesc: StoreDescriptor = swi.store; const storeAddedVersion = storeDesc.versionAdded ?? 0; - if (storeAddedVersion <= oldVersion) { - continue; - } let s: IDBObjectStore; - // Be tolerant if object store already exists. - // Probably means somebody deployed without - // adding the "addedInVersion" attribute. - if (!upgradeTransaction.objectStoreNames.contains(swi.storeName)) { - try { - s = db.createObjectStore(swi.storeName, { - autoIncrement: storeDesc.autoIncrement, - keyPath: storeDesc.keyPath, - }); - } catch (e) { - const moreInfo = e instanceof Error ? ` Reason: ${e.message}` : ""; - throw Error( - `Migration failed. Could not create store ${swi.storeName}.${moreInfo}`, - ); + if (storeAddedVersion > oldVersion) { + // Be tolerant if object store already exists. + // Probably means somebody deployed without + // adding the "addedInVersion" attribute. + if (!upgradeTransaction.objectStoreNames.contains(swi.storeName)) { + try { + s = db.createObjectStore(swi.storeName, { + autoIncrement: storeDesc.autoIncrement, + keyPath: storeDesc.keyPath, + }); + } catch (e) { + const moreInfo = e instanceof Error ? ` Reason: ${e.message}` : ""; + throw Error( + `Migration failed. Could not create store ${swi.storeName}.${moreInfo}`, + ); + } } - } else { - s = upgradeTransaction.objectStore(swi.storeName); } + + s = upgradeTransaction.objectStore(swi.storeName); + for (const indexName in swi.indexMap as any) { const indexDesc: IndexDescriptor = swi.indexMap[indexName]; const indexAddedVersion = indexDesc.versionAdded ?? 0; -- cgit v1.2.3