db-migrate / db-migrate/node-db-migrate
.db-migraterc at the root of the project is being ignored
- Dominant language
- JavaScript
- Stars
- 2.3k
- Forks
- 361
- PR merge metrics
- No merged PRs in 30d
Description
## I'm submitting a...
- [X] Bug report
- [ ] Feature request
- [ ] Question
## Current behavior
It seems `db-migrate` is completely ignoring the project's `.db-migraterc`. What am I doing wrong?
Based on what was discussed in #451 and #698: Is this feature really working? If it is, what are the supported properties for `.db-migraterc`?
Also: how does it merge `.db-migraterc` and `database.json`, exactly? [The documentation](https://db-migrate.readthedocs.io/en/latest/Getting%20Started/configuration/#rc-configs) doesn't enter in much details about that, so I just assumed anything that I put in `database.json`, or in any of the environments, could be put in `.db-migraterc` to be used as defaults.
## Expected behavior
It should load all configurations in `.db-migraterc`, and merge with those in `configFile` (or `database.json`, if it's not specified).
## Minimal reproduction of the problem with instructions
Follows my configuration:
```
flisboac@REDACTED:~/workspaces/REDACTED$ npm list db-migrate db-migrate-mysql
REDACTED@0.1.0 /home/flisboac/REDACTED
├── db-migrate@1.0.0-beta.16
└── db-migrate-mysql@2.2.0
flisboac@NOTE-BR-101:~/workspaces/REDACTED$ tree -a -L 1 --dirsfirst --si "$(pwd)"
/home/flisboac/REDACTED
├── [4.1k] .git
├── [4.1k] .husky
├── [4.1k] .vscode
├── [4.1k] dist
├── [4.1k] docs
├── [4.1k] etc
├── [4.1k] local
├── [ 20k] node_modules
├── [4.1k] scripts
├── [4.1k] src
├── [ 178] .db-migraterc
├── [ 369] .editorconfig
├── [3.6k] .env.local
├── [ 929] .env.local.sample
├── [ 119] .eslintignore
├── [ 920] .eslintrc.js
├── [ 19] .gitattributes
├── [ 679] .gitignore
├── [ 99] .prettierrc
├── [ 600] .release-it.js
├── [ 663] Dockerfile
├── [ 91] README.md
├── [2.0k] commitlint.config.js
├── [ 687] database.json
├── [1.5k] docker-compose.yml
├── [ 138] lint-staged.config.js
├── [289k] package-lock.json
├── [3.1k] package.json
└── [ 675] tsconfig.json
```
Contents of `.db-migraterc`:
```json
{
"defaultEnv": { "ENV": "APP_ENV" },
"migrationsDir": "src/migrations",
"driver": "mysql",
"multipleStatements": true,
"table": "migration_history",
"state": "migration_state"
}
```
Contents of `database.json`:
```json
{
"local": {
"host": { "ENV": "APP_DB_MASTER_HOST" },
"port": { "ENV": "APP_DB_MASTER_PORT" },
"username": "root",
"password": { "ENV": "APP_DB_ROOT_PASS" },
"database": { "ENV": "APP_DB_NAME" }
}
}
```
Contents of `.env.local`:
```sh
APP_ENV=local
# Rest of the .env file contains the APP_DB_ variables referenced in database.json
```
Result of calling db-migrate:
```
flisboac@REDACTED:~/workspaces/REDACTED$ npx dotenv-cli -e .env.local db-migrate create baseline --sql-file
npx: installed 10 in 1.471s
[ERROR] uncaughtException
[ERROR] Error: Environment(s) 'dev, development' not found.
at Config.exports.setCurrent (/home/flisboac/workspaces/REDACTED/node_modules/db-migrate/lib/config.js:23:11)
at Object.exports.loadObject (/home/flisboac/workspaces/REDACTED/node_modules/db-migrate/lib/config.js:188:9)
at Object.exports.loadFile (/home/flisboac/workspaces/REDACTED/node_modules/db-migrate/lib/config.js:94:18)
at loadConfig (/home/flisboac/workspaces/REDACTED/node_modules/db-migrate/lib/commands/helper/load-config.js:12:18)
at new dbmigrate (/home/flisboac/workspaces/REDACTED/node_modules/db-migrate/api.js:81:43)
at Object.module.exports.getInstance (/home/flisboac/workspaces/REDACTED/node_modules/db-migrate/index.js:84:10)
at /home/flisboac/workspaces/REDACTED/node_modules/db-migrate/bin/db-migrate:32:25
at /home/flisboac/workspaces/REDACTED/node_modules/resolve/lib/async.js:133:25
at maybeRealpath (/home/flisboac/workspaces/REDACTED/node_modules/resolve/lib/async.js:41:9)
at /home/flisboac/workspaces/REDACTED/node_modules/resolve/lib/async.js:129:24
at ondir (/home/flisboac/workspaces/REDACTED/node_modules/resolve/lib/async.js:309:27)
at onex (/home/flisboac/workspaces/REDACTED/node_modules/resolve/lib/async.js:201:32)
at /home/flisboac/workspaces/REDACTED/node_modules/resolve/lib/async.js:13:20
at FSReqCallback.oncomplete (fs.js:193:5)
```
And even if I just put `"defaultEnv": "local"` in `database.json`, it completely ignores the `migrationsDir` configuration, and just creates a migration in the `migrations` folder instead, at the root of my project.
## What is the motivation / use case for changing the behavior?
No behaviour change is being proposed.
## Environment
- **db-migrate version**: 1.0.0-beta.16
- **plugins with versions**: _(none)_
- **db-migrate driver with versions**:
- **db-migrate-mysql**: 2.2.0 _(not that it would make much difference, but here it goes!)_
### Additional information:
- **Node version**: v14.17.5
- **Platform**: Linux (WSL2)
### Others:
```
flisboac@REDACTED:~/workspaces/REDACTED$ uname -a
Linux REDACTED 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
```
Contributor guide
Assessment
This issue has not been assessed yet.