aboutsummaryrefslogtreecommitdiffstats
path: root/lib/migrate.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-18 07:49:25 -0800
committerAdam Soltys <[email protected]>2026-02-18 07:49:25 -0800
commitb1e3435613ef092d43353d511b632a8de64efc5d (patch)
treea300812eec33177505dbba5882d25669fea4243e /lib/migrate.ts
parent6e5c851fe1c4e7402014c5a42c8a5f919365a2c7 (diff)
downloadcoinos-server-b1e3435613ef092d43353d511b632a8de64efc5d.tar.gz
coinos-server-b1e3435613ef092d43353d511b632a8de64efc5d.zip
migrate funds to tb
Diffstat (limited to 'lib/migrate.ts')
-rw-r--r--lib/migrate.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/migrate.ts b/lib/migrate.ts
index 79f9546c..d4bfd61a 100644
--- a/lib/migrate.ts
+++ b/lib/migrate.ts
@@ -4,6 +4,8 @@ import { l, warn } from "$lib/logging";
import {
createBalanceAccount,
createCreditAccounts,
+ createFundAccount,
+ tbFundCredit,
tbSetBalance,
tbSetPending,
tbSetCredit,
@@ -176,4 +178,35 @@ export const migrateAutowithdraw = async () => {
return count;
};
+export const migrateFundsToTB = async () => {
+ const migrated = await db.get("tb:funds-migrated");
+ if (migrated) return 0;
+
+ let count = 0;
+
+ for await (const k of scan("fund:*")) {
+ try {
+ // Skip sub-keys like fund:name:payments, fund:name:managers, fund:limit
+ const parts = k.split(":");
+ if (parts.length !== 2) continue;
+ const name = parts[1];
+ if (name === "limit") continue;
+
+ const keyType = await db.type(k);
+ if (keyType !== "string") continue;
+
+ const balance = Number.parseInt((await db.get(k)) || "0");
+ await createFundAccount(name);
+ if (balance > 0) await tbFundCredit(name, balance);
+ count++;
+ } catch (e) {
+ warn("failed to migrate fund", k, e.message);
+ }
+ }
+
+ await db.set("tb:funds-migrated", Date.now().toString());
+ l(`Migrated ${count} funds to TigerBeetle`);
+ return count;
+};
+
export default migrate;