-
Notifications
You must be signed in to change notification settings - Fork 183
/
pretest.js
46 lines (39 loc) · 1.39 KB
/
pretest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
// Node module: loopback-connector-mysql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'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 || 'test';
process.env.MYSQL_PASSWORD =
process.env.MYSQL_PASSWORD || process.env.MYSQL_PASSWORD || 'test';
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);
});