Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show latest url to docs for macro.migrate #2900

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sqlx-cli/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,33 @@ 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!

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
);
}

Expand Down
Loading