fix(sqlx-cli): pass the DATABASE_URL to command spawned for sqlx-macros (#1735)

This commit is contained in:
LovecraftianHorror 2022-03-09 10:24:00 -06:00 committed by GitHub
parent dfd9cf59f1
commit feff96c460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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!(
@ -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",
@ -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`.
@ -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()?
};