db-migrate / db-migrate/node-db-migrate
db-migraten not working with ENV variables
- Dominant language
- JavaScript
- Stars
- 2.3k
- Forks
- 361
- PR merge metrics
- No merged PRs in 30d
Description
I'm using PM2 to run the node server and set env from PM2 config file. When I run db-migration command, it doesn't get node ENV variables and its value. But I can console it in my application. Even in normal .env not working for db-migrate
- [x] Bug report
# My db-migrate json file
```
{
"defaultEnv": {
"ENV": "NODE_ENV"
},
"local": {
"host": {
"ENV": "DB_HOST"
},
"user": {
"ENV": "DB_USER"
},
"password": {
"ENV": "DB_PASS"
},
"database": {
"ENV": "DATABASE"
},
"driver": "mysql",
"multipleStatements": true
},
}
```
# PM2 pm2.config.js
```
module.exports = {
apps : [
{
name: "abc_app",
script: "app.js",
exec_mode : "cluster",
instances: 0,
merge_logs: true,
time: true,
env_local: {
ENV : "local",
NODE_ENV : "local",
DB_HOST: "localhost",
DB_USER : "abc",
DB_PASS : "abc",
DATABASE : "abc"
}
}
]
}
```
# .env
```
DB_HOST = localhost
DB_USER = abc
DB_PASS = abc
DATABASE = abc
ENV = "local",
NODE_ENV = "local",
```
First I ran the node server by pm2 start pm2.config.js --env local (when pm2 using) OR node app.js(when .env using)
And run the db-migrate for migration, it throws an error as below
cmd: **db-migrate up -e local**
Error throws:
```
[ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
at module.exports (project/node_modules/db-migrate/lib/commands/helper/assert.js:9:14)
at project/node_modules/db-migrate/lib/commands/up.js:19:14
at project/node_modules/db-migrate/connect.js:17:7
at project/node_modules/db-migrate/lib/driver/index.js:95:9
at Handshake. (project/node_modules/db-migrate-mysql/index.js:510:14)
at Handshake. (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/Connection.js:526:10)
at Handshake._callback (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/Connection.js:488:16)
at Handshake.Sequence.end (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
at Handshake.ErrorPacket (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/sequences/Handshake.js:125:8)
at Handshake.Sequence._packetToError (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket. (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/Connection.js:88:28)
at Socket. (project/node_modules/db-migrate-mysql/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:298:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
```
Please help me to resolve this.
Contributor guide
Assessment
This issue has not been assessed yet.