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';
|
2016-08-09 20:29:47 +00:00
|
|
|
|
2017-05-12 14:13:15 +00:00
|
|
|
if (!process.env.CI) {
|
2016-08-18 18:24:31 +00:00
|
|
|
return console.log('Not seeding DB with test db');
|
2016-08-05 02:40:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 18:45:05 +00:00
|
|
|
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 || 'test';
|
|
|
|
process.env.MYSQL_PASSWORD =
|
|
|
|
process.env.MYSQL_PASSWORD || process.env.MYSQL_PASSWORD || 'test';
|
2016-08-18 18:24:31 +00:00
|
|
|
|
2020-08-28 06:43:09 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const cp = require('child_process');
|
2016-08-05 02:40:08 +00:00
|
|
|
|
2020-08-28 06:43:09 +00:00
|
|
|
const sql = fs.createReadStream(require.resolve('./test/schema.sql'));
|
|
|
|
const stdio = ['pipe', process.stdout, process.stderr];
|
|
|
|
const args = ['--user=' + process.env.MYSQL_USER];
|
2016-08-05 02:40:08 +00:00
|
|
|
|
2019-05-21 18:45:05 +00:00
|
|
|
if (process.env.MYSQL_HOST) {
|
|
|
|
args.push('--host=' + process.env.MYSQL_HOST);
|
2016-08-05 02:40:08 +00:00
|
|
|
}
|
2019-05-21 18:45:05 +00:00
|
|
|
if (process.env.MYSQL_PORT) {
|
|
|
|
args.push('--port=' + process.env.MYSQL_PORT);
|
2016-08-05 02:40:08 +00:00
|
|
|
}
|
2019-05-21 18:45:05 +00:00
|
|
|
if (process.env.MYSQL_PASSWORD) {
|
|
|
|
args.push('--password=' + process.env.MYSQL_PASSWORD);
|
2016-08-05 02:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('seeding DB with example db...');
|
2020-08-28 06:43:09 +00:00
|
|
|
const mysql = cp.spawn('mysql', args, {stdio: stdio});
|
2016-08-05 02:40:08 +00:00
|
|
|
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
|
|
|
});
|