diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index f8f4db74..ca2e22bc 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -24,7 +24,7 @@ struct DataFile { pub fn run(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result<()> { let db_kind = get_db_kind(url)?; - let data = run_prepare_step(merge, cargo_args)?; + let data = run_prepare_step(url, merge, cargo_args)?; if data.is_empty() { println!( @@ -54,7 +54,7 @@ pub fn run(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result<() pub fn check(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result<()> { let db_kind = get_db_kind(url)?; - let data = run_prepare_step(merge, cargo_args)?; + let data = run_prepare_step(url, merge, cargo_args)?; let data_file = File::open("sqlx-data.json").context( "failed to open `sqlx-data.json`; you may need to run `cargo sqlx prepare` first", @@ -80,7 +80,7 @@ pub fn check(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result< Ok(()) } -fn run_prepare_step(merge: bool, cargo_args: Vec) -> anyhow::Result { +fn run_prepare_step(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result { anyhow::ensure!( Path::new("Cargo.toml").exists(), r#"Failed to read `Cargo.toml`. @@ -126,6 +126,7 @@ hint: This command only works in the manifest directory of a Cargo package."# .args(cargo_args) .env("RUSTFLAGS", rustflags) .env("SQLX_OFFLINE", "false") + .env("DATABASE_URL", url) .status()? } else { Command::new(&cargo) @@ -141,6 +142,7 @@ hint: This command only works in the manifest directory of a Cargo package."# SystemTime::UNIX_EPOCH.elapsed()?.as_millis() )) .env("SQLX_OFFLINE", "false") + .env("DATABASE_URL", url) .status()? };