Skip to content

Commit 6a31c32

Browse files
authored
fix(cli): always set head using the up/down cli commands (#105)
Fixes an error where using the `up` command caused an error because `head` has not set
1 parent a1f3f65 commit 6a31c32

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/cli.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ yargs.command(
310310
const hasChanged = await adapter.waitForPending(CLI_LOGGER)
311311

312312
if (hasChanged) {
313-
process.stdout.write('The migrations have changed, reloading..\n\n')
313+
process.stdout.write('The pending migrations have changed, reloading..\n\n')
314314
continue
315315
}
316316
// create pending tasks
@@ -363,7 +363,11 @@ const migrationCommand = (type: TaskType) => async (argv: MigrationCommandArgv)
363363
await adapter.init()
364364
const tasks = argv.migrations!.map(name => new Task({ type, migration: new Migration(name) }))
365365
while (true) {
366-
await adapter.waitForPending(CLI_LOGGER)
366+
if (await adapter.waitForPending(CLI_LOGGER)) {
367+
process.stdout.write('The pending migrations have changed, reloading..\n\n')
368+
// retry
369+
continue
370+
}
367371
const head = await getHead()
368372
for (const task of tasks) {
369373
try {
@@ -377,19 +381,19 @@ const migrationCommand = (type: TaskType) => async (argv: MigrationCommandArgv)
377381
}
378382
}
379383
}
380-
break
381-
}
382-
for (const task of tasks) {
383-
process.stdout.write(`${task.toString()} ...`)
384-
const interval = setInterval(() => process.stdout.write('.'), 100)
385-
try {
386-
await task.execute(argv.migrationOutDir!, adapter)
387-
} finally {
388-
clearInterval(interval)
384+
for (const task of tasks) {
385+
process.stdout.write(`${task.toString()} ...`)
386+
const interval = setInterval(() => process.stdout.write('.'), 100)
387+
try {
388+
await task.execute(argv.migrationOutDir!, adapter, head)
389+
} finally {
390+
clearInterval(interval)
391+
}
392+
process.stdout.write(' Success\n')
389393
}
390-
process.stdout.write(' Success\n')
394+
process.stdout.write('\n' + chalk.green.bold('Migration successful') + '\n')
395+
break
391396
}
392-
process.stdout.write('\n' + chalk.green.bold('Migration successful') + '\n')
393397
} catch (err) {
394398
process.stderr.write('\n' + chalk.red(err.stack))
395399
process.exit(1)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class Status {
6262
const hasChanged = await adapter.waitForPending(logger)
6363

6464
if (hasChanged) {
65-
logger.log('The migrations have changed, reloading..\n\n')
65+
logger.log('The pending migrations have changed, reloading..\n\n')
6666
continue
6767
}
6868
// create pending tasks

0 commit comments

Comments
 (0)