loopback-connector-mysql/pretest.js

47 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2020-02-08 22:23:33 +00:00
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
2019-05-07 17:25:30 +00:00
// Node module: loopback-connector-mysql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
2016-08-10 18:41:03 +00:00
'use strict';
if (!process.env.CI) {
return console.log('Not seeding DB with test db');
}
process.env.MYSQL_HOST =
process.env.MYSQL_HOST || process.env.MYSQL_HOST || 'localhost';
process.env.MYSQL_PORT =
process.env.MYSQL_PORT || process.env.MYSQL_PORT || 3306;
process.env.MYSQL_USER =
process.env.MYSQL_USER || process.env.MYSQL_USER || 'root';
process.env.MYSQL_PASSWORD =
process.env.MYSQL_PASSWORD || process.env.MYSQL_PASSWORD || 'root';
const fs = require('fs');
const cp = require('child_process');
const sql = fs.createReadStream(require.resolve('./test/schema.sql'));
const stdio = ['pipe', process.stdout, process.stderr];
const args = ['--user=' + process.env.MYSQL_USER];
if (process.env.MYSQL_HOST) {
args.push('--host=' + process.env.MYSQL_HOST);
}
if (process.env.MYSQL_PORT) {
args.push('--port=' + process.env.MYSQL_PORT);
}
if (process.env.MYSQL_PASSWORD) {
args.push('--password=' + process.env.MYSQL_PASSWORD);
}
console.log('seeding DB with example db...');
const mysql = cp.spawn('mysql', args, {stdio: stdio});
sql.pipe(mysql.stdin);
mysql.on('exit', function(code) {
console.log('done seeding DB');
setTimeout(function() {
process.exit(code);
}, 200);
});