diff --git a/sqlx-cli/src/db.rs b/sqlx-cli/src/db.rs index 9596dfae0..aaa1fc7aa 100644 --- a/sqlx-cli/src/db.rs +++ b/sqlx-cli/src/db.rs @@ -1,4 +1,3 @@ -use crate::migrator::DatabaseMigrator; use dialoguer::Confirmation; use anyhow::bail; diff --git a/sqlx-cli/src/lib.rs b/sqlx-cli/src/lib.rs index 96fbdce7a..a833fe0f1 100644 --- a/sqlx-cli/src/lib.rs +++ b/sqlx-cli/src/lib.rs @@ -23,7 +23,7 @@ pub enum Command { /// /// Saves data for all invocations of `query!()` and friends in the project so that it may be /// built in offline mode, i.e. so compilation does not require connecting to a running database. - /// Outputs to `sqlx-data.json` in the current directory. + /// Outputs to `sqlx-data.json` in the current directory, overwriting it if it already exists. /// /// Offline mode can be activated simply by removing `DATABASE_URL` from the environment or /// building without a `.env` file. @@ -36,6 +36,10 @@ pub enum Command { /// Intended for use in CI. #[structopt(long)] check: bool, + + /// Any arguments to pass to `cargo check`. + #[structopt(name = "Cargo args", last = true)] + cargo_args: Vec, }, } @@ -77,8 +81,14 @@ pub async fn run(cmd: Command) -> anyhow::Result<()> { DatabaseCommand::Create => db::run_create().await?, DatabaseCommand::Drop => db::run_drop().await?, }, - Command::Prepare { check: false } => prepare::run()?, - Command::Prepare { check: true } => prepare::check()?, + Command::Prepare { + check: false, + cargo_args, + } => prepare::run(cargo_args)?, + Command::Prepare { + check: true, + cargo_args, + } => prepare::check(cargo_args)?, }; Ok(()) diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index d701cb9f0..4ed0eec62 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -12,7 +12,7 @@ use url::Url; type QueryData = BTreeMap; type JsonObject = serde_json::Map; -pub fn run() -> anyhow::Result<()> { +pub fn run(cargo_args: Vec) -> anyhow::Result<()> { #[derive(serde::Serialize)] struct DataFile { db: &'static str, @@ -21,7 +21,7 @@ pub fn run() -> anyhow::Result<()> { } let db_kind = get_db_kind()?; - let data = run_prepare_step()?; + let data = run_prepare_step(cargo_args)?; serde_json::to_writer_pretty( File::create("sqlx-data.json").context("failed to create/open `sqlx-data.json`")?, @@ -37,9 +37,9 @@ pub fn run() -> anyhow::Result<()> { Ok(()) } -pub fn check() -> anyhow::Result<()> { +pub fn check(cargo_args: Vec) -> anyhow::Result<()> { let db_kind = get_db_kind()?; - let data = run_prepare_step()?; + let data = run_prepare_step(cargo_args)?; let data_file = fs::read("sqlx-data.json").context( "failed to open `sqlx-data.json`; you may need to run `cargo sqlx prepare` first", @@ -70,13 +70,14 @@ pub fn check() -> anyhow::Result<()> { Ok(()) } -fn run_prepare_step() -> anyhow::Result { +fn run_prepare_step(cargo_args: Vec) -> anyhow::Result { // path to the Cargo executable let cargo = env::var("CARGO") .context("`prepare` subcommand may only be invoked as `cargo sqlx prepare``")?; let check_status = Command::new(&cargo) .arg("check") + .args(cargo_args) // set an always-changing env var that the macros depend on via `env!()` .env( "__SQLX_RECOMPILE_TRIGGER",