Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do knex migration examples pass the Promise constructor as a second argument?

Knex uses migration files to apply or roll back database structural changes. To create a new migration file, for example, one can use the cli:

knex migrate:make migration_name

This generates a file in the /migrations directory containing:

exports.up = function(knex, Promise) {

};

exports.down = function(knex, Promise) {

};

My question is, why is this passing Promise as an argument? I see that knex makes heavy internal use of Bluebird, and passes Promise to the migration. Is this, then, a vestige from pre-Promise ubiquity? Or... is it that to purposefully overwrite the es6 implementation so it can make use of nonstandard methods like tap and spread?

Any clarity would be much appreciated.

like image 494
Fissure King Avatar asked Feb 01 '26 03:02

Fissure King


1 Answers

If I recall correctly it was originally added there because es5 didn't have global Promise object.

It is not a documented feature, but for now the Promise passed to migration script is bluebird promise (https://github.com/tgriesser/knex/blob/master/src/migrate/index.js#L327).

However safest choice for future compatibility is to import promise from bluebird by yourself instead of using the one passed to the migration if you like to use special functions from bluebird.

like image 140
Mikael Lepistö Avatar answered Feb 03 '26 16:02

Mikael Lepistö