-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Setting SQLX_OFFLINE=true
in .env
breaks cargo sqlx prepare --workspace
#3836
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
Comments
Made some progress debugging this. I noticed that if I pin all my libraries to use |
Likely caused by #3815. In retrospect, unconditionally overriding the environment with values from The core bug that #3815 was trying to fix was the statefulness of environment variables. This is inherently unsound anyway due to
Ultimately, we shouldn't need to modify the environment anyway; that's not really idiomatic to Rust. The current API of It looks like the rewrite of Ultimately, it seems like we need to implement our own routine to read an environment variable or fall back to reading from the cc @joeydewaal |
Completely missed this, the suggested solution sounds trivial. I'll try to fix this. |
pls how have this issue gone |
I have found these related issues/pull requests
Description
I've been happily using sqlx w/ the CLI & offline mode for ~ a year now, but am just now running into some tooling issues in SQLx CLI. I suspect there is a subtle bug in SQLx, but I am not sure.
I have tried this with both SQLx CLI 7.4 & the most recent 8.5 and get the same issue. Please let me know if you know whats wrong.
I have had these two lines in my
.env
for a year:And I have been able to run
cargo sqlx prepare --workspace
which generates the.sqlx
files and thencargo build/watch
works as expected using the offline mode. All is great.However, recently, if I try to run
cargo sqlx prepare --workspace
whileSQLX_OFFLINE=true
is in my.env
, the command fails with many failures that imply it cannot find the .sqlx files, e.g. these errors:I can fix this error by deleting
SQLX_OFFLINE=true
from my.env
, and then runningcargo sqlx prepare --workspace
again. Everything works fine and I see the normal affirmative:I can then add
SQLX_OFFLINE=true
back to my .env and runcargo build/watch
. I would much prefer to not need to do this dance of deleting the line from.env
and then adding it back anytime I need to runprepare
.I haven't made any significant architectural changes to my app and I suspect the issue may be related to the effort to support multiple crates/db urls, but I am not sure.
I have a single
.env
file at the top level of my monorepo and would expect this to work given the documentation implying theprepare
is meant to ignore the offline env var and will always connect to the DB.Anyone have any ideas? Am I doing something wrong? Did somethinge change that I need to update?
I appreciate all the work you all put into SQLx. Thanks!
Reproduction steps
I suspect will be hard to reproduce my exact setup but the basic setup is:
.env
. Assume the database exists at the URL and we are able to connect.cargo sqlx prepare --workspace
and it fails with errors:I delete
SQLX_OFFLINE=true
, leading theDATABASE_URL
in .envI re-run
cargo sqlx prepare --workspace
, it succeedsSQLx version
SQLX - 0.8.5
Tried multiple CLI versions:
SQLxCLI - 7.4 & 8.4 & 8.5
Enabled SQLx features
I installed via
cargo install sqlx-cli --no-default-features --features native-tls,postgres
. Only use postgres.Database server and version
Postgres 16.x
Operating system
M4 Mac. Postgres running in AMD64 docker container.
Rust version
rustc 1.85.1 (4eb161250 2025-03-15)
The text was updated successfully, but these errors were encountered: