-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Reading DATABASE_URL from .env files implicitly can be very dangerous/potentially destructive #3722
Comments
A lot of commands can be dangerous/destructive if run in the wrong folder. If this is a serious concern for you, perhaps you might consider not using For the most destructive commands ( |
I like using .env files. I just don't expect every command I run to load and run with them implicitly.
I agree that this is probably true. But I'm struggling to think of one that works this way just by implicitly reading a magic (and hidden) file in that folder |
Well, I'm happy to discuss alternatives but otherwise there isn't really anything actionable here. |
I think a reasonable and non-breaking change would be to have a top-level switch like
|
@abonander I have opened a PR that addresses my concerns about this. Please let me know if this is something you're interested in. Thanks! |
I have found these related issues/pull requests
Somewhat related to #3061
Description
sqlx cli reads
DATABASE_URL
from.env
files implicitly which can be very dangerous and potentially destructive when running database commands against different environments (prod, staging, dev, etc.)It is easy to accidentally run a migrate run/revert against a database that you did not intend to just by accidentally being in the wrong directory. Is it not sufficient for the developer to use something like
dotenv
,foreman
, etc. like they normally do to explicitly load their.env
files into the environment when running sqlx commands? This is much safer and less surprising. "Principle of Least Surprise" and all that.Reproduction steps
Run an sqlx migrate command whilst in a directory with a .env file pointing to a server different than the one you thought (maybe you just changed directories, or are working in a script).
SQLx version
sqlx-cli 0.7.4
Enabled SQLx features
"chrono", "postgres", "runtime-tokio"
Database server and version
PG 14
Operating system
macOS
Rust version
rustc 1.84.0 (9fc6b4312 2025-01-07)
The text was updated successfully, but these errors were encountered: