commit fceb99fe6da2c92ba5069b63057f53aa064de29b
parent 943f5cb45c913f154fad9f77448c2c30133dff04
Author: Florian Dold <dold@taler.net>
Date: Thu, 6 Aug 2026 20:52:05 +0200
wallet-cli: add a command to migrate the wallet database
Issue: https://bugs.taler.net/n/11718
Diffstat:
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
@@ -85,6 +85,7 @@ import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import { JsonMessage, runRpcServer } from "@gnu-taler/taler-util/twrpc";
import {
createNativeWalletHost2,
+ getSqlite3FilenameFromStoragePath,
inspectWalletDbPath,
nativeCrypto,
rollbackWalletDbMigration,
@@ -574,7 +575,9 @@ async function createLocalWallet(
checkEnvFlag("TALER_WALLET_STATS"),
skipDefaults: walletCliArgs.wallet.skipDefaults,
},
- features: {},
+ features: {
+ ...(args.migrateNativeDb ? { migrateNativeDb: true } : {}),
+ },
},
} satisfies InitRequest,
);
@@ -601,6 +604,11 @@ function writeObservabilityLog(notif: WalletNotification): void {
export interface WalletRunArgs {
lazyTaskLoop?: boolean;
noInit?: boolean;
+ /**
+ * Migrate the database to the native schema during initialization, for the
+ * command that exists to do exactly that.
+ */
+ migrateNativeDb?: boolean;
}
async function withWallet<T>(
@@ -2915,6 +2923,36 @@ const advancedCli = walletCli.subcommand("advancedArgs", "advanced", {
addApiCommand(advancedCli, "advancedApi", "api");
advancedCli
+ .subcommand("dbMigrate", "db-migrate", {
+ help: "Migrate the wallet database to the native schema.",
+ })
+ .action(async (args) => {
+ const dbPath = getSqlite3FilenameFromStoragePath(
+ args.wallet.walletDbFile ?? defaultWalletDbPath,
+ );
+ // Through a wallet rather than against the file: initializing is what
+ // replays the old backend's fixup log, and the records the migration
+ // copies have to be the repaired ones.
+ await withWallet(
+ args,
+ { lazyTaskLoop: true, migrateNativeDb: true },
+ async () => {},
+ );
+ // The wallet logs a failed migration and keeps running on the database it
+ // had, which is right for a wallet starting up and wrong for a command
+ // whose only job was to migrate.
+ const after = await inspectWalletDbPath(dbPath);
+ if (after.kind !== "native") {
+ console.error(
+ `migration did not happen: ${dbPath} is still ${after.kind}.` +
+ ` See the log above for why.`,
+ );
+ processExit(1);
+ }
+ console.log(j2s({ dbPath, ...after }));
+ });
+
+advancedCli
.subcommand("dbMigrationInfo", "db-migration-info", {
help: "Show which schema a wallet database file uses.",
})