Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with warnPromise when migration does not return a promise.… #2730

Merged
merged 1 commit into from Jul 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/migrate/index.js
Expand Up @@ -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));
Expand All @@ -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();
}
);
});
}

Expand All @@ -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;
Expand Down