kawadhiya21 / mysql-migrations

A tool to use with mysql package to maintain migrations
MIT License
31 stars 25 forks source link

Callback / Promise return from migration #4

Open jfritzbarnes opened 6 years ago

jfritzbarnes commented 6 years ago

I want to use this within my tests to allow me to create a test database and run my tests against the test database using all of the migrations in the script. However, I run into a problem in that migration() does not take a callback argument or return a promise enabling it to be used in a situation where I need to not run following code until the migration completes.

The way I'd like to use this:

const migration = require('mysql-migrations');

before((done) => {
 const connection = mysql.createPool({
    connectionLimit: 10,
    host: process.env.MYSQL_HOST,
    user: process.env.MYSQL_USER,
    password: process.env.MYSQL_PASSWORD,
    database: process.env.MYSQL_DATABASE,
  });

  migration.init(connection, path.resolve(__dirname, '../migrations'), done);
}

I'm actually using await/async syntax but a callback will allow me the functionality I need.

jfritzbarnes commented 6 years ago

One thing I noticed is that my example above is not entirely correct. I need to modify argv via process.argv = ['test', 'test', 'up']; since the migrations.init assumes it is being run on the command line.