diff --git a/sqlx-cli/src/lib.rs b/sqlx-cli/src/lib.rs index ab83fdf6..2dae5520 100644 --- a/sqlx-cli/src/lib.rs +++ b/sqlx-cli/src/lib.rs @@ -1,8 +1,7 @@ use crate::opt::{Command, DatabaseCommand, MigrateCommand}; -use anyhow::{anyhow, bail}; +use anyhow::anyhow; use dotenv::dotenv; use std::env; -use std::path::Path; mod database; // mod migration; @@ -14,13 +13,6 @@ mod prepare; pub use crate::opt::Opt; pub async fn run(opt: Opt) -> anyhow::Result<()> { - if !Path::new("Cargo.toml").exists() { - bail!( - r#"Failed to read `Cargo.toml`. -hint: This command only works in the manifest directory of a Cargo package."# - ); - } - dotenv().ok(); let database_url = match opt.database_url { diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index 7d643ee2..37ef7781 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -6,7 +6,7 @@ use sqlx::any::{AnyConnectOptions, AnyKind}; use std::collections::BTreeMap; use std::fs::File; use std::io::{BufReader, BufWriter}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; use std::time::SystemTime; @@ -23,6 +23,12 @@ pub fn run(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result<() data: QueryData, } + anyhow::ensure!( + Path::new("Cargo.toml").exists(), + r#"Failed to read `Cargo.toml`. +hint: This command only works in the manifest directory of a Cargo package."# + ); + let db_kind = get_db_kind(url)?; let data = run_prepare_step(merge, cargo_args)?;