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`)