diff options
author | Florian Dold <florian@dold.me> | 2023-02-20 15:07:30 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-02-20 15:07:30 +0100 |
commit | 85c5c6d7c7304801fd223abea724fe67a56ff5fa (patch) | |
tree | c5df5887547567eca2883056e481818954821726 | |
parent | 6b28885f0bfaf4ae4d6073db360f67088bda7a17 (diff) |
wallet-core: fix DB migration logic when only an index is added
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 48 |
1 files changed, 24 insertions, 24 deletions
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<unknown> = 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; |