aboutsummaryrefslogtreecommitdiffstats
path: root/lib/migrate.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/migrate.js')
-rw-r--r--lib/migrate.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/migrate.js b/lib/migrate.js
index b2c094e3..a523fb27 100644
--- a/lib/migrate.js
+++ b/lib/migrate.js
@@ -1,3 +1,4 @@
+import { err } from "$lib/logging";
import { types } from "$lib/payments";
import { archive, db, g } from "$lib/db";
@@ -19,11 +20,11 @@ async function migrate(id) {
.set(`${id}:contacts`, (await archive.get(`${id}:contacts`)) || "[]")
.set(
`credit:bitcoin:${id}`,
- (await archive.get(`credit:bitcoin:${id}`)) || 0,
+ (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)
@@ -42,7 +43,7 @@ async function migrate(id) {
multi = await multi
.lPush(`${id}:payments`, pid)
.set(`payment:${pid}`, JSON.stringify(p));
- }),
+ })
);
let invoices = await archive.lRange(`${id}:invoices`, 0, -1);
@@ -52,16 +53,29 @@ async function migrate(id) {
multi = await multi
.lPush(`${id}:invoices`, iid)
.set(`invoice:${iid}`, inv);
- }),
+ })
);
await multi.exec();
delete q[id];
- await migrate(Object.keys(q)[0]);
return user;
}
}
+let keepMigrating = async () => {
+ try {
+ if (Object.keys(q).length) {
+ await migrate(Object.keys(q)[0]);
+ }
+ } catch (e) {
+ err("problem migrating", e.message);
+ }
+
+ setTimeout(keepMigrating, 100);
+};
+
+keepMigrating();
+
export default migrate;