gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 02/02: wallet-core: backwards compatibility for bank


From: gnunet
Subject: [taler-wallet-core] 02/02: wallet-core: backwards compatibility for bankAccounts store, naming conventions
Date: Fri, 23 Sep 2022 21:00:56 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

commit 8d19b801538e2be842ebe2d03ca464f72bb95edb
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Sep 23 21:00:51 2022 +0200

    wallet-core: backwards compatibility for bankAccounts store, naming 
conventions
---
 packages/taler-wallet-core/src/db-utils.ts   | 26 +++++++++++++++++++++++++-
 packages/taler-wallet-core/src/db.ts         |  5 +++--
 packages/taler-wallet-core/src/util/query.ts | 14 ++++++++++++++
 packages/taler-wallet-core/src/wallet.ts     |  4 ++--
 4 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/packages/taler-wallet-core/src/db-utils.ts 
b/packages/taler-wallet-core/src/db-utils.ts
index 2cb1b12fe..88960e6b1 100644
--- a/packages/taler-wallet-core/src/db-utils.ts
+++ b/packages/taler-wallet-core/src/db-utils.ts
@@ -70,7 +70,31 @@ function upgradeFromStoreMap(
     return;
   }
   logger.info(`upgrading database from ${oldVersion} to ${newVersion}`);
-  throw Error("upgrade not supported");
+  for (const n in storeMap) {
+    const swi: StoreWithIndexes<any, StoreDescriptor<unknown>, any> = storeMap[
+      n
+    ];
+    const storeDesc: StoreDescriptor<unknown> = swi.store;
+    const storeAddedVersion = storeDesc.versionAdded ?? 0;
+    if (storeAddedVersion <= oldVersion) {
+      continue;
+    }
+    const s = db.createObjectStore(swi.storeName, {
+      autoIncrement: storeDesc.autoIncrement,
+      keyPath: storeDesc.keyPath,
+    });
+    for (const indexName in swi.indexMap as any) {
+      const indexDesc: IndexDescriptor = swi.indexMap[indexName];
+      const indexAddedVersion = indexDesc.versionAdded ?? 0;
+      if (indexAddedVersion <= oldVersion) {
+        continue;
+      }
+      s.createIndex(indexDesc.name, indexDesc.keyPath, {
+        multiEntry: indexDesc.multiEntry,
+        unique: indexDesc.unique,
+      });
+    }
+  }
 }
 
 function promiseFromTransaction(transaction: IDBTransaction): Promise<void> {
diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index c33e1c3fb..3bbe5f002 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -96,7 +96,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
  * backwards-compatible way or object stores and indices
  * are added.
  */
-export const WALLET_DB_MINOR_VERSION = 1;
+export const WALLET_DB_MINOR_VERSION = 2;
 
 export namespace OperationStatusRange {
   export const ACTIVE_START = 10;
@@ -2088,6 +2088,7 @@ export const WalletStoresV1 = {
     "bankAccounts",
     describeContents<BankAccountsRecord>({
       keyPath: "uri",
+      versionAdded: 2,
     }),
     {},
   ),
@@ -2099,7 +2100,7 @@ export const WalletStoresV1 = {
 export interface BankAccountsRecord {
   uri: string;
   currency: string;
-  kyc_completed: boolean;
+  kycCompleted: boolean;
   alias: string;
 }
 
diff --git a/packages/taler-wallet-core/src/util/query.ts 
b/packages/taler-wallet-core/src/util/query.ts
index 71d7b9783..47f38a3a1 100644
--- a/packages/taler-wallet-core/src/util/query.ts
+++ b/packages/taler-wallet-core/src/util/query.ts
@@ -284,17 +284,29 @@ export interface IndexDescriptor {
   keyPath: IDBKeyPath | IDBKeyPath[];
   multiEntry?: boolean;
   unique?: boolean;
+  versionAdded?: number;
 }
 
 export interface StoreDescriptor<RecordType> {
   _dummy: undefined & RecordType;
   keyPath?: IDBKeyPath | IDBKeyPath[];
   autoIncrement?: boolean;
+  /**
+   * Database version that this store was added in, or
+   * undefined if added in the first version.
+   */
+  versionAdded?: number;
 }
 
 export interface StoreOptions {
   keyPath?: IDBKeyPath | IDBKeyPath[];
   autoIncrement?: boolean;
+
+  /**
+   * Database version that this store was added in, or
+   * undefined if added in the first version.
+   */
+  versionAdded?: number;
 }
 
 export function describeContents<RecordType = never>(
@@ -304,6 +316,7 @@ export function describeContents<RecordType = never>(
     keyPath: options.keyPath,
     _dummy: undefined as any,
     autoIncrement: options.autoIncrement,
+    versionAdded: options.versionAdded,
   };
 }
 
@@ -317,6 +330,7 @@ export function describeIndex(
     name,
     multiEntry: options.multiEntry,
     unique: options.unique,
+    versionAdded: options.versionAdded,
   };
 }
 
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index dd47d7ce3..3b9a323a7 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -686,7 +686,7 @@ async function listKnownBankAccounts(
           accounts.push({
             uri: payto,
             alias: r.alias,
-            kyc_completed: r.kyc_completed,
+            kyc_completed: r.kycCompleted,
             currency: r.currency,
           });
         }
@@ -710,7 +710,7 @@ async function addKnownBankAccounts(
         uri: payto,
         alias: alias,
         currency: currency,
-        kyc_completed: false,
+        kycCompleted: false,
       });
     });
   return;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]