feat: add database selector env variable

This commit is contained in:
Sérgio Salgado 2021-09-01 17:23:44 +01:00 committed by Josh Harvey
parent 8db565c609
commit 005503a995
3 changed files with 11 additions and 8 deletions

1
.env Normal file
View file

@ -0,0 +1 @@
LAMASSU_DB=DEV

View file

@ -2,8 +2,14 @@ const fs = require('fs')
const path = require('path')
const os = require('os')
const argv = require('minimist')(process.argv.slice(2))
const _ = require('lodash/fp')
const dotenv = require('dotenv').config()
const STRESS_TEST_DB = 'psql://postgres:postgres123@localhost/lamassu_stress'
const dbMapping = psqlConf => ({
STRESS_TEST: _.replace('lamassu', 'lamassu_stress', psqlConf),
RELEASE: _.replace('lamassu', 'lamassu_release', psqlConf),
DEV: _.replace('lamassu', 'lamassu', psqlConf)
})
/**
* @return {{path: string, opts: any}}
@ -32,9 +38,7 @@ function load () {
opts: JSON.parse(fs.readFileSync(globalConfigPath))
}
if (argv.testDB) {
config.opts.postgresql = STRESS_TEST_DB
}
config.opts.postgresql = dbMapping(config.opts.postgresql)[process.env.LAMASSU_DB]
return config
} catch (_) {
@ -45,9 +49,7 @@ function load () {
opts: JSON.parse(fs.readFileSync(homeConfigPath))
}
if (argv.testDB) {
config.opts.postgresql = STRESS_TEST_DB
}
config.opts.postgresql = dbMapping(config.opts.postgresql)[process.env.LAMASSU_DB]
return config
} catch (_) {

View file

@ -3,5 +3,5 @@ const cmd = require('./scripts')
process.on('message', async (msg) => {
console.log('Message from parent:', msg)
await cmd.execCommand(`node --prof ../../bin/lamassu-server --mockSms --testDB`)
await cmd.execCommand(`node --prof LAMASSU_DB=STRESS_TEST ../../bin/lamassu-server --mockSms`)
})