-
Notifications
You must be signed in to change notification settings - Fork 179
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
fix(cli)!: ensure env vars are set before migrating #1222
base: main
Are you sure you want to change the base?
Conversation
Should this be seen as a breaking change? 🤔 |
Kind of yes, because it would prevent the migration from running w/o specifying a URL or env vars. The previous check is ignored since |
Okay, I will think about it Would it be okay for you if this fix wont immediately merged because of that? |
Alright, I'll also take a look at some other open issues |
if (!cp.host && !cp.port && !cp.database) { | ||
if ( | ||
!process.env[argv[databaseUrlVarArg]] && | ||
(!process.env.PGHOST || !cp.user || !cp.database) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (if-minor): you removed the check for !cp.host && !cp.port
, but added !cp.user
and used ||
(or). Can you explain a bit why you did it like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cp.host
and cp.port
are unlikely to be undefined
since we read pg
defaults, which set host
to 'localhost'
and port
to '5432'
if missing.
When running pg
locally without any env vars, node-pg-migrate
would run but give an error due to an undefined
password string/function. Adding a check for the pw alone isn't enough because it would still cause a connection error if pg
isn't running locally (also when pw is set but others vars aren't).
so, if there's no dburl
, I check if any required variable or process.env.PGHOST
is missing and stop it
fixes #1220
pg
library defaultshost
to 'localhost' whenPGHOST
environment variable is missing, potentially leading to unintended database connections, To mitigate this, we now perform an explicit check to ensure thePGHOST
environment variable is set.Default Config
Reference: