wallet-core: fix DB migration logic when only an index is added

This commit is contained in:
Florian Dold 2023-02-20 15:07:30 +01:00
parent 6b28885f0b
commit 85c5c6d7c7
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -118,7 +118,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
* backwards-compatible way or object stores and indices * backwards-compatible way or object stores and indices
* are added. * are added.
*/ */
export const WALLET_DB_MINOR_VERSION = 4; export const WALLET_DB_MINOR_VERSION = 5;
/** /**
* Ranges for operation status fields. * Ranges for operation status fields.
@ -2291,7 +2291,7 @@ export const WalletStoresV1 = {
"byExchangeAndContractPriv", "byExchangeAndContractPriv",
["exchangeBaseUrl", "contractPriv"], ["exchangeBaseUrl", "contractPriv"],
{ {
versionAdded: 4, versionAdded: 5,
unique: true, unique: true,
}, },
), ),
@ -2299,7 +2299,7 @@ export const WalletStoresV1 = {
"byWithdrawalGroupId", "byWithdrawalGroupId",
"withdrawalGroupId", "withdrawalGroupId",
{ {
versionAdded: 4, versionAdded: 5,
}, },
), ),
byStatus: describeIndex("byStatus", "status"), byStatus: describeIndex("byStatus", "status"),
@ -2319,7 +2319,7 @@ export const WalletStoresV1 = {
"byExchangeAndContractPriv", "byExchangeAndContractPriv",
["exchangeBaseUrl", "contractPriv"], ["exchangeBaseUrl", "contractPriv"],
{ {
versionAdded: 4, versionAdded: 5,
unique: true, unique: true,
}, },
), ),
@ -2337,7 +2337,7 @@ export const WalletStoresV1 = {
"byWithdrawalGroupId", "byWithdrawalGroupId",
"withdrawalGroupId", "withdrawalGroupId",
{ {
versionAdded: 4, versionAdded: 5,
}, },
), ),
}, },
@ -2663,10 +2663,8 @@ function upgradeFromStoreMap(
]; ];
const storeDesc: StoreDescriptor<unknown> = swi.store; const storeDesc: StoreDescriptor<unknown> = swi.store;
const storeAddedVersion = storeDesc.versionAdded ?? 0; const storeAddedVersion = storeDesc.versionAdded ?? 0;
if (storeAddedVersion <= oldVersion) {
continue;
}
let s: IDBObjectStore; let s: IDBObjectStore;
if (storeAddedVersion > oldVersion) {
// Be tolerant if object store already exists. // Be tolerant if object store already exists.
// Probably means somebody deployed without // Probably means somebody deployed without
// adding the "addedInVersion" attribute. // adding the "addedInVersion" attribute.
@ -2682,9 +2680,11 @@ function upgradeFromStoreMap(
`Migration failed. Could not create store ${swi.storeName}.${moreInfo}`, `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) { for (const indexName in swi.indexMap as any) {
const indexDesc: IndexDescriptor = swi.indexMap[indexName]; const indexDesc: IndexDescriptor = swi.indexMap[indexName];
const indexAddedVersion = indexDesc.versionAdded ?? 0; const indexAddedVersion = indexDesc.versionAdded ?? 0;