Skip to content

Commit

Permalink
script per pds
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Nov 9, 2023
1 parent 704a9c3 commit f0c6f05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/pds/src/migrate-script/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schema>({
dialect: new SqliteDialect({
database: new SqliteDB(LOCATION),
database: sqliteDb,
}),
})
}
Expand Down
8 changes: 7 additions & 1 deletion packages/pds/src/migrate-script/migrate-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit f0c6f05

Please sign in to comment.