@@ -109,11 +109,6 @@ pub async fn add(
109
109
) -> anyhow:: Result < ( ) > {
110
110
fs:: create_dir_all ( migration_source) . context ( "Unable to create migrations directory" ) ?;
111
111
112
- // if the migrations directory is empty
113
- let has_existing_migrations = fs:: read_dir ( migration_source)
114
- . map ( |mut dir| dir. next ( ) . is_some ( ) )
115
- . unwrap_or ( false ) ;
116
-
117
112
let migrator = Migrator :: new ( Path :: new ( migration_source) ) . await ?;
118
113
// Type of newly created migration will be the same as the first one
119
114
// or reversible flag if this is the first migration
@@ -144,6 +139,11 @@ pub async fn add(
144
139
) ?;
145
140
}
146
141
142
+ // if the migrations directory is empty
143
+ let has_existing_migrations = fs:: read_dir ( migration_source)
144
+ . map ( |mut dir| dir. next ( ) . is_some ( ) )
145
+ . unwrap_or ( false ) ;
146
+
147
147
if !has_existing_migrations {
148
148
let quoted_source = if migration_source != "migrations" {
149
149
format ! ( "{migration_source:?}" )
@@ -163,7 +163,7 @@ sqlx::migrate!({}).run(<&your_pool OR &mut your_connection>).await?;
163
163
Note that the compiler won't pick up new migrations if no Rust source files have changed.
164
164
You can create a Cargo build script to work around this with `sqlx migrate build-script`.
165
165
166
- See: https://docs.rs/sqlx/0.5 /sqlx/macro.migrate.html
166
+ See: https://docs.rs/sqlx/latest /sqlx/macro.migrate.html
167
167
"# ,
168
168
quoted_source
169
169
) ;
@@ -228,7 +228,7 @@ pub async fn info(migration_source: &str, connect_opts: &ConnectOpts) -> anyhow:
228
228
) ,
229
229
) ;
230
230
println ! (
231
- "local migration has checksum {}" ,
231
+ "local migration has checksum {}" ,
232
232
short_checksum( & migration. checksum)
233
233
)
234
234
}
@@ -268,7 +268,7 @@ pub async fn run(
268
268
) -> anyhow:: Result < ( ) > {
269
269
let migrator = Migrator :: new ( Path :: new ( migration_source) ) . await ?;
270
270
if let Some ( target_version) = target_version {
271
- if !migrator. iter ( ) . any ( |m| target_version == m . version ) {
271
+ if !migrator. version_exists ( target_version) {
272
272
bail ! ( MigrateError :: VersionNotPresent ( target_version) ) ;
273
273
}
274
274
}
@@ -363,7 +363,7 @@ pub async fn revert(
363
363
) -> anyhow:: Result < ( ) > {
364
364
let migrator = Migrator :: new ( Path :: new ( migration_source) ) . await ?;
365
365
if let Some ( target_version) = target_version {
366
- if target_version != 0 && !migrator. iter ( ) . any ( |m| target_version == m . version ) {
366
+ if target_version != 0 && !migrator. version_exists ( target_version) {
367
367
bail ! ( MigrateError :: VersionNotPresent ( target_version) ) ;
368
368
}
369
369
}
0 commit comments