Skip to content

Commit d798f73

Browse files
authored
fix: save tasks to db sequentially (#123)
1 parent 8e7ecef commit d798f73

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/cli.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ yargs.command(
287287
try {
288288
const adapter = createAdapterFromUrl(argv.db!)
289289
await adapter.init()
290-
while (true) {
290+
outerLoop: while (true) {
291291
const head = await getHead()
292292
const status = await getStatus(adapter, head)
293293
process.stdout.write(status.toString())
@@ -313,23 +313,20 @@ yargs.command(
313313
process.stdout.write('The pending migrations have changed, reloading..\n\n')
314314
continue
315315
}
316-
// create pending tasks
317-
for (const task of tasks) {
318-
try {
319-
task.head = head
320-
await adapter.beginMigrationTask(task)
321-
} catch (error) {
322-
if (error instanceof PendingMigrationFoundError) {
323-
continue
324-
} else {
325-
throw error
326-
}
327-
}
328-
}
329316

330317
for (const commit of status.newCommits) {
331318
process.stdout.write(`${chalk.yellow(commit.shortSha1)} ${commit.subject}\n`)
332319
for (const task of commit.tasks) {
320+
try {
321+
task.head = head
322+
await adapter.beginMigrationTask(task)
323+
} catch (error) {
324+
if (error instanceof PendingMigrationFoundError) {
325+
continue outerLoop
326+
} else {
327+
throw error
328+
}
329+
}
333330
process.stdout.write(task.toString() + ' ...')
334331
const interval = setInterval(() => process.stdout.write('.'), 100)
335332
try {

0 commit comments

Comments
 (0)