From fd576b3cb70c9138e031063c9ab7dfdacda3b6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Lid=C3=A9n?= Date: Wed, 25 Jul 2018 08:10:53 +0200 Subject: [PATCH] Fix issues with warnPromise when migration does not return a promise. Fixes #2725 --- src/migrate/index.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/migrate/index.js b/src/migrate/index.js index 55d57dcb2e..dc342c6b15 100644 --- a/src/migrate/index.js +++ b/src/migrate/index.js @@ -354,7 +354,11 @@ export default class Migrator { if (!trx && this._useTransaction(migration, disableTransactions)) { return this._transaction(migration, direction, name); } - return warnPromise(migration[direction](trxOrKnex, Promise), name); + return warnPromise( + this.knex, + migration[direction](trxOrKnex, Promise), + name + ); }) .then(() => { log.push(path.join(directory, name)); @@ -379,9 +383,14 @@ export default class Migrator { _transaction(migration, direction, name) { return this.knex.transaction((trx) => { - return warnPromise(migration[direction](trx, Promise), name, () => { - trx.commit(); - }); + return warnPromise( + this.knex, + migration[direction](trx, Promise), + name, + () => { + trx.commit(); + } + ); }); } @@ -408,9 +417,9 @@ function validateMigrationList(migrations) { } } -function warnPromise(value, name, fn) { +function warnPromise(knex, value, name, fn) { if (!value || typeof value.then !== 'function') { - this.knex.client.logger.warn(`migration ${name} did not return a promise`); + knex.client.logger.warn(`migration ${name} did not return a promise`); if (fn && typeof fn === 'function') fn(); } return value;