wallet-core: fix DB migration logic when only an index is added
This commit is contained in:
parent
6b28885f0b
commit
85c5c6d7c7
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user