Skip to content

Commit

Permalink
Doc link fixed
Browse files Browse the repository at this point in the history
Indentation for readability
Moved variable declaration for readability
  • Loading branch information
dcodesdev committed Dec 29, 2023
1 parent 929af41 commit 2ba21c9
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions sqlx-cli/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ pub async fn add(
) -> anyhow::Result<()> {
fs::create_dir_all(migration_source).context("Unable to create migrations directory")?;

// if the migrations directory is empty
let has_existing_migrations = fs::read_dir(migration_source)
.map(|mut dir| dir.next().is_some())
.unwrap_or(false);

let migrator = Migrator::new(Path::new(migration_source)).await?;
// Type of newly created migration will be the same as the first one
// or reversible flag if this is the first migration
Expand Down Expand Up @@ -144,6 +139,11 @@ pub async fn add(
)?;
}

// if the migrations directory is empty
let has_existing_migrations = fs::read_dir(migration_source)
.map(|mut dir| dir.next().is_some())
.unwrap_or(false);

if !has_existing_migrations {
let quoted_source = if migration_source != "migrations" {
format!("{migration_source:?}")
Expand All @@ -153,18 +153,18 @@ pub async fn add(

print!(
r#"
Congratulations on creating your first migration!
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:
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!({}).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`.
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/0.5/sqlx/macro.migrate.html
"#,
See: https://docs.rs/sqlx/latest/sqlx/macro.migrate.html
"#,
quoted_source
);
}
Expand Down

0 comments on commit 2ba21c9

Please sign in to comment.