2016-08-09 20:29:47 +00:00
|
|
|
// TODO: used for testing support for parallel testing on ci.strongloop.com which
|
|
|
|
// provides MYSQL_* env vars instead of TEST_MYSQL_* env vars.
|
|
|
|
process.env.TEST_MYSQL_USER = process.env.TEST_MYSQL_USER || process.env.MYSQL_USER;
|
|
|
|
process.env.TEST_MYSQL_PASSWORD = process.env.TEST_MYSQL_PASSWORD || process.env.MYSQL_PASSWORD;
|
|
|
|
process.env.TEST_MYSQL_HOST = process.env.TEST_MYSQL_HOST || process.env.MYSQL_HOST;
|
|
|
|
process.env.TEST_MYSQL_PORT = process.env.TEST_MYSQL_PORT || process.env.MYSQL_PORT;
|
|
|
|
|
2016-08-05 02:40:08 +00:00
|
|
|
if (!process.env.TEST_MYSQL_USER) {
|
|
|
|
console.log('not seeding DB with example db');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var cp = require('child_process');
|
|
|
|
|
2016-08-10 00:25:57 +00:00
|
|
|
var sql = fs.createReadStream(require.resolve('./test/schema.sql'));
|
2016-08-05 02:40:08 +00:00
|
|
|
var stdio = ['pipe', process.stdout, process.stderr];
|
|
|
|
var args = ['--user=' + process.env.TEST_MYSQL_USER];
|
|
|
|
|
|
|
|
if (process.env.TEST_MYSQL_HOST) {
|
|
|
|
args.push('--host=' + process.env.TEST_MYSQL_HOST);
|
|
|
|
}
|
|
|
|
if (process.env.TEST_MYSQL_PORT) {
|
|
|
|
args.push('--port=' + process.env.TEST_MYSQL_PORT);
|
|
|
|
}
|
|
|
|
if (process.env.TEST_MYSQL_PASSWORD) {
|
|
|
|
args.push('--password=' + process.env.TEST_MYSQL_PASSWORD);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('seeding DB with example db...');
|
|
|
|
var mysql = cp.spawn('mysql', args, {stdio: stdio});
|
|
|
|
sql.pipe(mysql.stdin);
|
2016-08-09 20:29:47 +00:00
|
|
|
mysql.on('exit', function(code) {
|
2016-08-05 02:40:08 +00:00
|
|
|
console.log('done seeding DB');
|
2016-08-09 20:29:47 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
process.exit(code);
|
|
|
|
}, 200);
|
2016-08-05 02:40:08 +00:00
|
|
|
});
|