feat: add database selector env variable
This commit is contained in:
parent
8db565c609
commit
005503a995
3 changed files with 11 additions and 8 deletions
1
.env
Normal file
1
.env
Normal file
|
|
@ -0,0 +1 @@
|
|||
LAMASSU_DB=DEV
|
||||
|
|
@ -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 (_) {
|
||||
|
|
|
|||
|
|
@ -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`)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue