-
Notifications
You must be signed in to change notification settings - Fork 180
/
pretest.js
36 lines (32 loc) · 1.38 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
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
// Node module: loopback-connector-postgresql
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
'use strict';
if (!process.env.CI) {
return console.log('not seeding DB with test db');
}
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];
process.env.PGHOST = process.env.TEST_POSTGRESQL_HOST ||
process.env.POSTGRESQL_HOST || process.env.PGHOST || 'localhost';
process.env.PGPORT = process.env.TEST_POSTGRESQL_PORT ||
process.env.POSTGRESQL_PORT || process.env.PGPORT || 5432;
process.env.PGUSER = process.env.TEST_POSTGRESQL_USER ||
process.env.POSTGRESQL_USER || process.env.PGUSER || 'test';
process.env.PGPASSWORD = process.env.TEST_POSTGRESQL_PASSWORD ||
process.env.POSTGRESQL_PASSWORD || process.env.PGPASSWORD || 'test';
console.log('seeding DB with test db...');
const args = process.env.POSTGRESQL_DATABASE ?
['-U', process.env.PGUSER, process.env.POSTGRESQL_DATABASE] :
['-U', process.env.PGUSER];
const psql = cp.spawn('psql', args, {stdio: stdio});
sql.pipe(psql.stdin);
psql.on('exit', function(code) {
console.log('done seeding DB');
setTimeout(function() {
process.exit(code);
}, 200);
});