diff options
| author | Adam Soltys <[email protected]> | 2026-02-05 09:34:17 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-06 09:00:09 -0800 |
| commit | 7c40346355346fb59a86d11cdbef1a7da00e8da8 (patch) | |
| tree | 4112444b006f5f9cfcd52a3783c305305fc21a55 /lib/migrate.ts | |
| parent | 1ebc40afc14a75d7fe157b2c6c20ffea9dedb5eb (diff) | |
| download | coinos-server-7c40346355346fb59a86d11cdbef1a7da00e8da8.tar.gz coinos-server-7c40346355346fb59a86d11cdbef1a7da00e8da8.zip | |
microsats
Diffstat (limited to 'lib/migrate.ts')
| -rw-r--r-- | lib/migrate.ts | 31 |
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; |
