-
Notifications
You must be signed in to change notification settings - Fork 84
/
pretest.js
34 lines (26 loc) · 1.43 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
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: loopback-connector-mssql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
require('./test/init');
const exec = require('child_process').exec;
const path = require('path');
const isWin = (process.platform === 'win32');
const sqlFileDir = path.resolve(__dirname, 'test', 'tables.sql');
const sqlDependencyDir = path.resolve(__dirname, 'node_modules', '.bin', 'sqlcmd');
if (!process.env.CI) {
return console.log('not seeding DB with test db');
}
if (!process.env.MSSQL_HOST) process.env.MSSQL_HOST = global.getConfig().host;
if (!process.env.MSSQL_PORT) process.env.MSSQL_PORT = global.getConfig().port;
if (!process.env.MSSQL_USER) process.env.MSSQL_USER = global.getConfig().user;
if (!process.env.MSSQL_PASSWORD) process.env.MSSQL_PASSWORD = global.getConfig().password;
if (!process.env.MSSQL_DATABASE) process.env.MSSQL_DATABASE = global.getConfig().database;
const catFileCmd = (isWin ? 'type ' : 'cat ') + sqlFileDir;
const sqlcmd = `${catFileCmd} | ${sqlDependencyDir} -s ${process.env.MSSQL_HOST} -o ${process.env.MSSQL_PORT} ` +
`-u "${process.env.MSSQL_USER}" -p "${process.env.MSSQL_PASSWORD}" -d "${process.env.MSSQL_DATABASE}"`;
exec(sqlcmd, function(err, result) {
if (err) return console.log('Database seeding failed.\n%s', err);
return console.log('Database successfully seeded.');
});