aboutsummaryrefslogtreecommitdiffstats
path: root/lib/migrate.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-13 21:07:55 -0800
committerAdam Soltys <[email protected]>2026-02-13 21:08:04 -0800
commitc7c6ee7ba59467b8ddcfe8196b4f7586a864f3c0 (patch)
treefccdf94755fb1b91c1de65e9d18f2f94742ebe09 /lib/migrate.ts
parentb2b9fe837db7308285909ec1b374546194405d00 (diff)
downloadcoinos-server-c7c6ee7ba59467b8ddcfe8196b4f7586a864f3c0.tar.gz
coinos-server-c7c6ee7ba59467b8ddcfe8196b4f7586a864f3c0.zip
account level currency and autowithdraw settings
Diffstat (limited to 'lib/migrate.ts')
-rw-r--r--lib/migrate.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/migrate.ts b/lib/migrate.ts
index 4b64bee5..d0e38276 100644
--- a/lib/migrate.ts
+++ b/lib/migrate.ts
@@ -136,4 +136,44 @@ export const migrateToMicrosats = async () => {
return count;
};
+export const migrateAutowithdraw = async () => {
+ const migrated = await db.get("autowithdraw:migrated");
+ if (migrated) return 0;
+
+ let count = 0;
+
+ for await (const k of db.scanIterator({ MATCH: "user:*" })) {
+ try {
+ const raw = await db.get(k);
+ if (!raw || !raw.startsWith("{")) continue;
+
+ const user = JSON.parse(raw);
+ if (!user.id || !user.autowithdraw) continue;
+
+ const accountIds = await db.lRange(`${user.id}:accounts`, 0, -1);
+
+ for (const aid of accountIds) {
+ const account = await g(`account:${aid}`);
+ if (!account) continue;
+ if (account.seed || account.type === "ark") continue;
+ if (account.autowithdraw) continue;
+
+ account.autowithdraw = true;
+ account.threshold = account.threshold ?? user.threshold;
+ account.reserve = account.reserve ?? user.reserve;
+ account.destination = account.destination ?? user.destination;
+
+ await s(`account:${aid}`, account);
+ count++;
+ }
+ } catch (e) {
+ warn("autowithdraw migration error", k, e.message);
+ }
+ }
+
+ await db.set("autowithdraw:migrated", Date.now().toString());
+ l(`Migrated autowithdraw to ${count} accounts`);
+ return count;
+};
+
export default migrate;