chore(useremails): add failsafe to scantable
This commit is contained in:
Родитель
21e56b13ab
Коммит
42b56751d3
|
@ -6,12 +6,12 @@ export const scanTableFactory = <TRecord extends object>({
|
|||
db: Knex<TRecord>
|
||||
}) =>
|
||||
async function* ({ tableName, batchSize }: { tableName: string; batchSize: number }) {
|
||||
const [rowsCount] = await db(tableName).count()
|
||||
const MAX_LIMIT = parseInt(rowsCount.count.toString())
|
||||
let offset = 0
|
||||
|
||||
while (offset <= MAX_LIMIT) {
|
||||
yield db<TRecord>(tableName).limit(batchSize).offset(offset)
|
||||
let rows = []
|
||||
do {
|
||||
rows = await db<TRecord>(tableName).limit(batchSize).offset(offset)
|
||||
yield rows
|
||||
offset += batchSize
|
||||
}
|
||||
} while (rows.length > 0 || offset > batchSize * 1000)
|
||||
}
|
||||
|
|
|
@ -35,12 +35,8 @@ export async function up(knex: Knex): Promise<void> {
|
|||
}
|
||||
currentIteration++
|
||||
coreLogger.debug(`Completed iteration ${currentIteration}`)
|
||||
|
||||
if (currentIteration > maxLoops + 2) {
|
||||
throw new Error('Stopping migration to avoid infinite loop')
|
||||
}
|
||||
}
|
||||
coreLogger.debug('Migration user_emails_backfill started')
|
||||
coreLogger.debug('Migration user_emails_backfill completed')
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
|
|
Загрузка…
Ссылка в новой задаче