From 6a31c32791780d127e534fdecc0b45ea6fa0d223 Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Sun, 17 Jun 2018 22:14:53 -0700 Subject: [PATCH] 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 --- src/cli.ts | 30 +++++++++++++++++------------- src/index.ts | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 1e57010..c71ab94 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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 @@ -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 { @@ -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) diff --git a/src/index.ts b/src/index.ts index 90fd494..5a89aef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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