-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(sqlx-cli): Add flag to disable automatic loading of .env files #3724
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abonander
requested changes
Feb 4, 2025
Co-authored-by: Austin Bonander <[email protected]>
jayy-lmao
pushed a commit
to jayy-lmao/sqlx
that referenced
this pull request
Mar 1, 2025
…aunchbadge#3724) * Add flag to disable automatic loading of .env files * Update sqlx-cli/src/opt.rs Co-authored-by: Austin Bonander <[email protected]> --------- Co-authored-by: Austin Bonander <[email protected]>
abonander
added a commit
that referenced
this pull request
Mar 2, 2025
* feat: add geometry path * fix: paths to pg point * test: remove array tests for path * Fix readme: uuid feature is gating for all repos (#3720) The readme previously stated that the uuid feature is only for postres but it actually also gates the functionality in mysql and sqlite. * Replace some futures_util APIs with std variants (#3721) * feat(sqlx-cli): Add flag to disable automatic loading of .env files (#3724) * Add flag to disable automatic loading of .env files * Update sqlx-cli/src/opt.rs Co-authored-by: Austin Bonander <[email protected]> --------- Co-authored-by: Austin Bonander <[email protected]> * chore: expose bstr feature (#3714) * chore: replace rustls-pemfile with rustls-pki-types (#3725) * QueryBuilder: add `debug_assert` when `push_values` is passed an empty set of tuples (#3734) * throw a warning in tracing so that the empty tuples would be noticed * use debug assertion to throw a panic in debug mode * fix: merge conflicts * chore(cli): remove unused async-trait crate from dependencies (#3754) * Update pull_request_template.md * Fix example calculation (#3741) * Avoid privilege requirements by using an advisory lock in test setup (postgres). (#3753) * feat(sqlx-postgres): use advisory lock to avoid setup race condition * fix(sqlx-postgres): numeric hex constants not supported before postgres 16 * Small doc correction. (#3755) When sqlx-core/src/from_row.rs was updated to implement FromRow for tuples of up to 16 values, a comment was left stating that it was implemented up to tuples of 9 values. * Update FAQ.md * refactor(cli): replace promptly with dialoguer (#3669) * docs(pool): recommend actix-web ThinData over Data to avoid two Arcs (#3762) Both actix_web::web::Data and sqlx::PgPool internally wrap an Arc. Thus, using Data<PgPool> as an extractor in an actix-web route handler results in two Arcs wrapping the data of interest, which isn't ideal. Actix-web 4.9.0 introduced a new web::ThinData extractor for cases like this, where the data is already wrapped in an `Arc` (or is otherwise similarly cheap and sensible to simply clone), which doesn't wrap the inner value in a (second) Arc. Since the new extractor is better suited to the task, suggest it in place of web::Data when giving an example on how to share a pool. * fix: merge conflicts * fix: use types mod from main * fix: merge conflicts * fix: merge conflicts * fix: merge conflicts * fix: ordering of types mod * fix: path import * test: no array test for path --------- Co-authored-by: Jon Thacker <[email protected]> Co-authored-by: Paolo Barbolini <[email protected]> Co-authored-by: Ben Wilber <[email protected]> Co-authored-by: Austin Bonander <[email protected]> Co-authored-by: joeydewaal <[email protected]> Co-authored-by: tottoto <[email protected]> Co-authored-by: Ethan Wang <[email protected]> Co-authored-by: Stefan Schindler <[email protected]> Co-authored-by: kildrens <[email protected]> Co-authored-by: Marti Serra <[email protected]> Co-authored-by: Jonas Malaco <[email protected]>
abonander
reviewed
Apr 14, 2025
Comment on lines
+18
to
+20
if !opt.no_dotenv { | ||
dotenvy::dotenv().ok(); | ||
} |
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.
Note: this PR actually regressed default handling of .env
files because it moves the dotenv()
call after the Clap parsing, which reads DATABASE_URL
from the environment.
Releasing a hotfix in #3824.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Does your PR solve an issue?
#3722
Automatic loading of
.env
files can be dangerous (and destructive). It is possible to run an sqlx database command against a database that you did not expect just by virtue of there being a hidden.env
file in the directory from which you ran the command.This PR adds a top-level switch to the
sqlx
CLI--no-dotenv
which will disable the automatic loading of.env
files. This makes it safer to use in scripts and allows developers to make loading.env
files explicit if they want.