Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using config-file and config-value #891

Open
mike-usa opened this issue Apr 26, 2022 · 2 comments
Open

Using config-file and config-value #891

mike-usa opened this issue Apr 26, 2022 · 2 comments

Comments

@mike-usa
Copy link

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"
  }
}
@mike-usa
Copy link
Author

mike-usa commented Apr 27, 2022

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:

  1. the version of config that is packaged with node-pg-migrate is out of date
  2. 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

@mike-usa
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant