From f0c6f053e40ce39f58a27e41ab1aeb01e2e2ea75 Mon Sep 17 00:00:00 2001 From: dholms Date: Wed, 8 Nov 2023 20:58:50 -0600 Subject: [PATCH] script per pds --- packages/pds/src/migrate-script/db.ts | 4 +++- packages/pds/src/migrate-script/migrate-all.ts | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/pds/src/migrate-script/db.ts b/packages/pds/src/migrate-script/db.ts index 6f1b2f7db21..0581d223b58 100644 --- a/packages/pds/src/migrate-script/db.ts +++ b/packages/pds/src/migrate-script/db.ts @@ -4,9 +4,11 @@ import SqliteDB from 'better-sqlite3' const LOCATION = 'migrate.db' export const getDb = (): MigrateDb => { + const sqliteDb = new SqliteDB(LOCATION) + sqliteDb.pragma('busy_timeout = 5000') return new Kysely({ dialect: new SqliteDialect({ - database: new SqliteDB(LOCATION), + database: sqliteDb, }), }) } diff --git a/packages/pds/src/migrate-script/migrate-all.ts b/packages/pds/src/migrate-script/migrate-all.ts index 42dafca54db..5cd4969a775 100644 --- a/packages/pds/src/migrate-script/migrate-all.ts +++ b/packages/pds/src/migrate-script/migrate-all.ts @@ -20,21 +20,27 @@ import { export const runScript = async () => { console.log('starting') const { db, ctx, adminHeaders, pdsInfos } = await setupEnv() + + const pdsIdArg = process.argv[2] + const pdsId = pdsIdArg ? parseInt(pdsIdArg) : null + const todo = await db .selectFrom('status') .where('status.phase', '<', 7) .where('failed', '=', 0) + .if(pdsId !== null, (qb) => qb.where('pdsId', '=', pdsId)) .orderBy('phase', 'desc') .orderBy('did') .selectAll() .execute() + let pdsCounter = 0 let completed = 0 let failed = 0 console.log('migrating: ', todo.length) - const migrateQueue = new PQueue({ concurrency: 150 }) + const migrateQueue = new PQueue({ concurrency: 100 }) process.on('SIGINT', async () => { migrateQueue.clear() console.log(`waiting on ${migrateQueue.pending} to finish`)