Skip to content

Commit feff96c

Browse files
fix(sqlx-cli): pass the DATABASE_URL to command spawned for sqlx-macros (transact-rs#1735)
1 parent dfd9cf5 commit feff96c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

sqlx-cli/src/prepare.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct DataFile {
2424

2525
pub fn run(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<()> {
2626
let db_kind = get_db_kind(url)?;
27-
let data = run_prepare_step(merge, cargo_args)?;
27+
let data = run_prepare_step(url, merge, cargo_args)?;
2828

2929
if data.is_empty() {
3030
println!(
@@ -54,7 +54,7 @@ pub fn run(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<()
5454

5555
pub fn check(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<()> {
5656
let db_kind = get_db_kind(url)?;
57-
let data = run_prepare_step(merge, cargo_args)?;
57+
let data = run_prepare_step(url, merge, cargo_args)?;
5858

5959
let data_file = File::open("sqlx-data.json").context(
6060
"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<
8080
Ok(())
8181
}
8282

83-
fn run_prepare_step(merge: bool, cargo_args: Vec<String>) -> anyhow::Result<QueryData> {
83+
fn run_prepare_step(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<QueryData> {
8484
anyhow::ensure!(
8585
Path::new("Cargo.toml").exists(),
8686
r#"Failed to read `Cargo.toml`.
@@ -126,6 +126,7 @@ hint: This command only works in the manifest directory of a Cargo package."#
126126
.args(cargo_args)
127127
.env("RUSTFLAGS", rustflags)
128128
.env("SQLX_OFFLINE", "false")
129+
.env("DATABASE_URL", url)
129130
.status()?
130131
} else {
131132
Command::new(&cargo)
@@ -141,6 +142,7 @@ hint: This command only works in the manifest directory of a Cargo package."#
141142
SystemTime::UNIX_EPOCH.elapsed()?.as_millis()
142143
))
143144
.env("SQLX_OFFLINE", "false")
145+
.env("DATABASE_URL", url)
144146
.status()?
145147
};
146148

0 commit comments

Comments
 (0)