Using config-file and config-value
mike-usa opened this issue · comments
How to properly use config-value
?
config/database.json
{
"dev": {
"user": "dev-user",
"password": "dev-pass",
"host": "localhost",
"port": 5432,
"database": "dev-db"
},
"test": {
"user": "test-user",
"password": "test-pass",
"host": "localhost",
"port": 5432,
"database": "test-db"
},
}
Given the documentation, my understanding is migrations can run against a specified database via config-value
and loaded from a non-standard json file via config-file
. However, the following command fails at loading the migration:
npx node-pg-migrate up --config-file config/database.json --config-value dev
For verification, a simplified config/database.json works without a named key:
{
"user": "dev-user",
"password": "dev-pass",
"host": "localhost",
"port": 5432,
"database": "dev-db"
}
npx node-pg-migrate up --config-file config/database.json
However, the following also results in an error when using a db key:
{
"db": {
"user": "dev-user",
"password": "dev-pass",
"host": "localhost",
"port": 5432,
"database": "dev-db"
}
}
I'm still reading through https://github.com/salsita/node-pg-migrate/blob/master/bin/node-pg-migrate, specifically the config-file
and config-value
portion, which seem independent. It seems like the file portion should come first and inside it should evaluate if the config-value was set.
I discovered it'll work if I install config
library independently and name the json file to match NODE_ENV
or NODE_CONFIG_ENV
value. Using the original example with dev and test keys
For config/database.json
npm i config
NODE_ENV=database nix node-pg-migrate up --config-value dev
To me this suggests a couple things:
- the version of config that is packaged with node-pg-migrate is out of date
- it demonstrates plenty of opportunity to extend the library; you may want multiple config files; one for the general environment settings and then one for database configurations -- think Ruby on Rails (or SailsJS)
Disclaimer: I don't perform much Node development. All of these libraries are fairly new to me. Feel free to set me straight.
Likewise this can work with modules as well:
// config/database.js
module.exports = {
"dev": {
"database": "dev",
"user": "dev-user",
...
},
"test": {
"database": "test"
...
}
}
NODE_ENV=database npx node-pg-migrate up --config-value test
I am suspicious that downloading the config
package was the difference. The version I'm using is 3.3.7 and the version packaged with node-pg-migrate is 3.3.6. I don't think that patch version update included such a substantial change. So maybe there must be something interfering with the config load process?