2016-04-25 10:59:00 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
let dbcheck = require('../../lib/dbcheck');
|
|
|
|
let log = require('npmlog');
|
2017-05-09 23:40:02 +00:00
|
|
|
let path = require('path');
|
|
|
|
let fs = require('fs');
|
2016-04-25 10:59:00 +00:00
|
|
|
|
|
|
|
log.level = 'verbose';
|
|
|
|
|
2017-05-09 23:40:02 +00:00
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
log.error('sqlinit', 'This script does not run in production');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'test' && !fs.existsSync(path.join(__dirname, '..', '..', 'config', 'test.toml'))) {
|
|
|
|
log.error('sqlinit', 'This script only runs in test if config/test.toml (i.e. a dedicated test database) is present');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2016-04-25 10:59:00 +00:00
|
|
|
dbcheck(err => {
|
|
|
|
if (err) {
|
|
|
|
log.error('DB', err);
|
|
|
|
return process.exit(1);
|
|
|
|
}
|
|
|
|
return process.exit(0);
|
|
|
|
});
|