mysql-migrations
mysql-migrations copied to clipboard
Callback / Promise return from migration
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.
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.