aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-28 10:45:07 -0800
committerAdam Soltys <[email protected]>2023-12-28 22:51:02 -0800
commit73a36051979e7257d9198bed976128e8cea5235d (patch)
treec5f9affff1b2dee7c36afdb7b8ae323055290d71 /lib
parent02a373b8128c1544711d14ecd6ed19e20c7e3b0b (diff)
downloadcoinos-server-73a36051979e7257d9198bed976128e8cea5235d.tar.gz
coinos-server-73a36051979e7257d9198bed976128e8cea5235d.zip
migrate script
Diffstat (limited to 'lib')
-rw-r--r--lib/migrate.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/migrate.js b/lib/migrate.js
index e8ae5993..81743934 100644
--- a/lib/migrate.js
+++ b/lib/migrate.js
@@ -1,6 +1,8 @@
+import { types } from "$lib/payments";
import { archive, db, g } from "$lib/db";
-export default async (id) => {
+let q = {};
+async function migrate(id) {
let user = JSON.parse(await archive.get(`user:${id}`));
if (typeof user === "string") {
@@ -14,11 +16,14 @@ export default async (id) => {
.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(`${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,
+ (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)
@@ -28,10 +33,15 @@ export default async (id) => {
let payments = await archive.lRange(`${id}:payments`, 0, -1);
await Promise.all(
payments.map(async (pid) => {
- let p = await archive.get(`payment:${pid}`);
+ let p = JSON.parse(await archive.get(`payment:${pid}`));
+ if (p.type === types.internal && p.ref) {
+ let recipient = await g(`user:${p.ref}`);
+ if (!recipient) q[p.ref] = true;
+ }
+
multi = await multi
.lPush(`${id}:payments`, pid)
- .set(`payment:${pid}`, p);
+ .set(`payment:${pid}`, JSON.stringify(p));
}),
);
@@ -47,6 +57,11 @@ export default async (id) => {
await multi.exec();
+ delete q[id];
+ await migrate(Object.keys(q)[0]);
+
return user;
}
-};
+}
+
+export default migrate;