aboutsummaryrefslogtreecommitdiffstats
path: root/lib/migrate.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/migrate.ts')
-rw-r--r--lib/migrate.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/migrate.ts b/lib/migrate.ts
index fe804107..4b64bee5 100644
--- a/lib/migrate.ts
+++ b/lib/migrate.ts
@@ -7,6 +7,7 @@ import {
tbSetBalance,
tbSetPending,
tbSetCredit,
+ tbMultiplyForMicrosats,
} from "$lib/tb";
async function migrate(id) {
@@ -105,4 +106,34 @@ export const migrateBalancesToTB = async () => {
return count;
};
+export const migrateToMicrosats = async () => {
+ const migrated = await db.get("tb:microsats");
+ if (migrated) return 0;
+
+ let count = 0;
+
+ // Iterate through all users and multiply their TB balances
+ for await (const k of db.scanIterator({ MATCH: "user:*" })) {
+ try {
+ const raw = await db.get(k);
+ if (!raw) continue;
+
+ // Skip user alias keys (they just contain another key reference)
+ if (!raw.startsWith("{")) continue;
+
+ const user = JSON.parse(raw);
+ if (!user.id) continue;
+
+ const multiplied = await tbMultiplyForMicrosats(user.id);
+ if (multiplied > 0) count++;
+ } catch (e) {
+ warn("microsats migration error", k, e.message);
+ }
+ }
+
+ await db.set("tb:microsats", Date.now().toString());
+ l(`Migrated ${count} users to microsats`);
+ return count;
+};
+
export default migrate;