Skip to content

Commit

Permalink
fix(sqlx-cli): pass the DATABASE_URL to command spawned for `sqlx-m…
Browse files Browse the repository at this point in the history
…acros` (#1735)
  • Loading branch information
CosmicHorrorDev authored Mar 9, 2022
1 parent dfd9cf5 commit feff96c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sqlx-cli/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct DataFile {

pub fn run(url: &str, merge: bool, cargo_args: Vec<String>) -> 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!(
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn run(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<()

pub fn check(url: &str, merge: bool, cargo_args: Vec<String>) -> 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",
Expand All @@ -80,7 +80,7 @@ pub fn check(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<
Ok(())
}

fn run_prepare_step(merge: bool, cargo_args: Vec<String>) -> anyhow::Result<QueryData> {
fn run_prepare_step(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<QueryData> {
anyhow::ensure!(
Path::new("Cargo.toml").exists(),
r#"Failed to read `Cargo.toml`.
Expand Down Expand Up @@ -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)
Expand All @@ -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()?
};

Expand Down

0 comments on commit feff96c

Please sign in to comment.