diff options
| author | Adam Soltys <[email protected]> | 2023-12-27 23:22:27 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-12-28 22:51:02 -0800 |
| commit | 02a373b8128c1544711d14ecd6ed19e20c7e3b0b (patch) | |
| tree | 51327752718eac827273ada093fe6060d7184f56 /lib/migrate.js | |
| parent | aaf8dd49b07066e534408a2d41d84c518a45c2b6 (diff) | |
| download | coinos-server-02a373b8128c1544711d14ecd6ed19e20c7e3b0b.tar.gz coinos-server-02a373b8128c1544711d14ecd6ed19e20c7e3b0b.zip | |
liquid wip
Diffstat (limited to 'lib/migrate.js')
| -rw-r--r-- | lib/migrate.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/migrate.js b/lib/migrate.js new file mode 100644 index 00000000..e8ae5993 --- /dev/null +++ b/lib/migrate.js @@ -0,0 +1,52 @@ +import { archive, db, g } from "$lib/db"; + +export default async (id) => { + let user = JSON.parse(await archive.get(`user:${id}`)); + + if (typeof user === "string") { + id = user; + user = JSON.parse(await archive.get(`user:${id}`)); + } + + if (user) { + let multi = await db + .multi() + .set(`user:${user.username}`, id) + .set(`user:${user.pubkey}`, id) + .set(`user:${id}`, JSON.stringify(user)) + .set(`${id}:contacts`, await archive.get(`${id}:contacts`)) + .set(`credit:bitcoin:${id}`, await archive.get(`credit:bitcoin:${id}`) || 0) + .set( + `credit:lightning:${id}`, + await archive.get(`credit:lightning:${id}`) || 0, + ) + .set(`${id}:lastlen`, (await archive.get(`${id}:lastlen`)) || 0) + .set(`${id}:cindex`, (await archive.get(`${id}:cindex`)) || 0) + .set(`balance:${id}`, (await archive.get(`balance:${id}`)) || 0) + .set(`pending:${id}`, (await archive.get(`pending:${id}`)) || 0); + + let payments = await archive.lRange(`${id}:payments`, 0, -1); + await Promise.all( + payments.map(async (pid) => { + let p = await archive.get(`payment:${pid}`); + multi = await multi + .lPush(`${id}:payments`, pid) + .set(`payment:${pid}`, p); + }), + ); + + let invoices = await archive.lRange(`${id}:invoices`, 0, -1); + await Promise.all( + invoices.map(async (iid) => { + let inv = await archive.get(`invoice:${iid}`); + multi = await multi + .lPush(`${id}:invoices`, iid) + .set(`invoice:${iid}`, inv); + }), + ); + + await multi.exec(); + + return user; + } +}; |
