Skip to content

Commit

Permalink
fix(cli): always set head using the up/down cli commands (#105)
Browse files Browse the repository at this point in the history
Fixes an error where using the `up` command caused an error because `head` has not set
  • Loading branch information
eseliger committed Jun 18, 2018
1 parent a1f3f65 commit 6a31c32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ yargs.command(
const hasChanged = await adapter.waitForPending(CLI_LOGGER)

if (hasChanged) {
process.stdout.write('The migrations have changed, reloading..\n\n')
process.stdout.write('The pending migrations have changed, reloading..\n\n')
continue
}
// create pending tasks
Expand Down Expand Up @@ -363,7 +363,11 @@ const migrationCommand = (type: TaskType) => async (argv: MigrationCommandArgv)
await adapter.init()
const tasks = argv.migrations!.map(name => new Task({ type, migration: new Migration(name) }))
while (true) {
await adapter.waitForPending(CLI_LOGGER)
if (await adapter.waitForPending(CLI_LOGGER)) {
process.stdout.write('The pending migrations have changed, reloading..\n\n')
// retry
continue
}
const head = await getHead()
for (const task of tasks) {
try {
Expand All @@ -377,19 +381,19 @@ const migrationCommand = (type: TaskType) => async (argv: MigrationCommandArgv)
}
}
}
break
}
for (const task of tasks) {
process.stdout.write(`${task.toString()} ...`)
const interval = setInterval(() => process.stdout.write('.'), 100)
try {
await task.execute(argv.migrationOutDir!, adapter)
} finally {
clearInterval(interval)
for (const task of tasks) {
process.stdout.write(`${task.toString()} ...`)
const interval = setInterval(() => process.stdout.write('.'), 100)
try {
await task.execute(argv.migrationOutDir!, adapter, head)
} finally {
clearInterval(interval)
}
process.stdout.write(' Success\n')
}
process.stdout.write(' Success\n')
process.stdout.write('\n' + chalk.green.bold('Migration successful') + '\n')
break
}
process.stdout.write('\n' + chalk.green.bold('Migration successful') + '\n')
} catch (err) {
process.stderr.write('\n' + chalk.red(err.stack))
process.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Status {
const hasChanged = await adapter.waitForPending(logger)

if (hasChanged) {
logger.log('The migrations have changed, reloading..\n\n')
logger.log('The pending migrations have changed, reloading..\n\n')
continue
}
// create pending tasks
Expand Down

0 comments on commit 6a31c32

Please sign in to comment.