db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Db migrate not using configuration in config file #750

Open Xexnon opened 3 years ago

Xexnon commented 3 years ago

please read the docs: https://db-migrate.readthedocs.io/en/latest/Getting%20Started/configuration/

Originally posted by @wzrdtales in https://github.com/db-migrate/node-db-migrate/issues/749#issuecomment-920919061

I followed the docs and this is my config file I'm using a database url

{
  "development": {
    "ENV": "DATABASE_DEV_URL",
    "driver": "mysql",
    "multipleStatements": true
  },
  "test": {
    "ENV": "DATABASE_TEST_URL",
    "driver": "mysql",
    "multipleStatements": true
  },
  "production": {
    "ENV": "DATABASE_URL",
    "driver": "mysql",
    "multipleStatements": true
  },
  "defaultEnv": {
    "ENV": "NODE_ENV"
  },
  "sql-file": true
}
dschinkel commented 3 years ago

common man. You couldn't have read the docs.

example: "user": {"ENV": "PRODUCTION_USERNAME"},

Nowhere in the docs does it say you can use ENV as a key in the json. It's a VALUE wrapped in {}

Nowhere in the docs does it say you can set defaultEnv to a Node Environment variable. You set it to a specific dbmigrate environment (e.g. test, development, etc.)

flisboac commented 2 years ago

I think "defaultEnv": { "ENV": "NODE_ENV" } should work, but other than that, @dschinkel is correct. You should use the idiom { "ENV": "ENV_VAR_NAME" } to reference an environment variable ENV_VAR_NAME at runtime.

You cannot replace DATABASE_URL everywhere (because I'm not sure every driver even have a single URL configuration property you can set), but you can replace some of the properties expected by each driver with an env-var configuration, e.g.:

{
  "development": {
    "driver": "mysql",
    "multipleStatements": true,
    "username": { "ENV": "DATABASE_USERNAME" },
    "password": { "ENV": "DATABASE_PASSWORD" } // etc, etc.
  },
  "defaultEnv": { "ENV": "NODE_ENV" }, // Just be sure that NODE_ENV has the correct driver name, e.g. development, production, etc
  "sql-file": true
}