summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/db.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2020-12-02 14:55:04 +0100
committerFlorian Dold <florian@dold.me>2020-12-02 14:55:04 +0100
commit89f1a281fea66b986fc0a003dc10446f6ed6e4a2 (patch)
tree8ffe90d572bc6967ee86bdcffc1eb6dc1240d17c /packages/taler-wallet-core/src/db.ts
parent0828e65f8845dc4b148c0d3b0697fb589b338239 (diff)
downloadwallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.gz
wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.bz2
wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.zip
backup WIP
Diffstat (limited to 'packages/taler-wallet-core/src/db.ts')
-rw-r--r--packages/taler-wallet-core/src/db.ts21
1 files changed, 15 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index ecc5509dc..6f5b6b453 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -1,7 +1,12 @@
import { Stores } from "./types/dbTypes";
import { openDatabase, Database, Store, Index } from "./util/query";
-import { IDBFactory, IDBDatabase, IDBObjectStore, IDBTransaction } from "idb-bridge";
-import { Logger } from './util/logging';
+import {
+ IDBFactory,
+ IDBDatabase,
+ IDBObjectStore,
+ IDBTransaction,
+} from "idb-bridge";
+import { Logger } from "./util/logging";
/**
* Name of the Taler database. This is effectively the major
@@ -18,7 +23,7 @@ const TALER_DB_NAME = "taler-wallet-prod-v1";
* backwards-compatible way or object stores and indices
* are added.
*/
-export const WALLET_DB_MINOR_VERSION = 2;
+export const WALLET_DB_MINOR_VERSION = 3;
const logger = new Logger("db.ts");
@@ -43,7 +48,9 @@ export function openTalerDatabase(
const s = db.createObjectStore(si.name, si.storeParams);
for (const indexName in si as any) {
if ((si as any)[indexName] instanceof Index) {
- const ii: Index<string, string, any, any> = (si as any)[indexName];
+ const ii: Index<string, string, any, any> = (si as any)[
+ indexName
+ ];
s.createIndex(ii.indexName, ii.keyPath, ii.options);
}
}
@@ -59,7 +66,8 @@ export function openTalerDatabase(
if ((Stores as any)[n] instanceof Store) {
const si: Store<string, any> = (Stores as any)[n];
let s: IDBObjectStore;
- if ((si.storeParams?.versionAdded ?? 1) > oldVersion) {
+ const storeVersionAdded = si.storeParams?.versionAdded ?? 1;
+ if (storeVersionAdded > oldVersion) {
s = db.createObjectStore(si.name, si.storeParams);
} else {
s = upgradeTransaction.objectStore(si.name);
@@ -67,7 +75,8 @@ export function openTalerDatabase(
for (const indexName in si as any) {
if ((si as any)[indexName] instanceof Index) {
const ii: Index<string, string, any, any> = (si as any)[indexName];
- if ((ii.options?.versionAdded ?? 0) > oldVersion) {
+ const indexVersionAdded = ii.options?.versionAdded ?? 0;
+ if (indexVersionAdded > oldVersion || storeVersionAdded > oldVersion) {
s.createIndex(ii.indexName, ii.keyPath, ii.options);
}
}