From 1e3292472fdfd51e431b36180caa51aae2d0da90 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Sun, 18 Feb 2024 18:39:45 -0800 Subject: [PATCH] fix: link to correct version in first-migration message --- sqlx-cli/src/migrate.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sqlx-cli/src/migrate.rs b/sqlx-cli/src/migrate.rs index 1ab8929fc1..e939f5bec8 100644 --- a/sqlx-cli/src/migrate.rs +++ b/sqlx-cli/src/migrate.rs @@ -151,6 +151,19 @@ pub async fn add( "".to_string() }; + // Provide a link to the current version in case the details change. + // Patch version is deliberately omitted. + let version = if let (Some(major), Some(minor)) = ( + // Don't fail if we're not being built by Cargo + option_env!("CARGO_PKG_VERSION_MAJOR"), + option_env!("CARGO_PKG_VERSION_MINOR"), + ) { + format!("{major}.{minor}") + } else { + // If a version isn't available, "latest" is fine. + "latest".to_string() + }; + print!( r#" Congratulations on creating your first migration! @@ -158,14 +171,13 @@ Congratulations on creating your first migration! Did you know you can embed your migrations in your application binary? On startup, after creating your database connection or pool, add: -sqlx::migrate!({}).run(<&your_pool OR &mut your_connection>).await?; +sqlx::migrate!({quoted_source}).run(<&your_pool OR &mut your_connection>).await?; Note that the compiler won't pick up new migrations if no Rust source files have changed. You can create a Cargo build script to work around this with `sqlx migrate build-script`. -See: https://docs.rs/sqlx/latest/sqlx/macro.migrate.html +See: https://docs.rs/sqlx/{version}/sqlx/macro.migrate.html "#, - quoted_source ); }