File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -224,21 +224,23 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
224
224
migration : & ' m Migration ,
225
225
) -> BoxFuture < ' m , Result < Duration , MigrateError > > {
226
226
Box :: pin ( async move {
227
+ // Use a single transaction for the actual migration script and the essential bookeeping so we never
228
+ // execute migrations twice. See https://github.com/launchbadge/sqlx/issues/1966.
227
229
let mut tx = self . begin ( ) . await ?;
228
230
let start = Instant :: now ( ) ;
229
231
230
232
let _ = tx. execute ( & * migration. sql ) . await ?;
231
233
232
- tx. commit ( ) . await ?;
233
-
234
- let elapsed = start. elapsed ( ) ;
235
-
236
234
// language=SQL
237
235
let _ = query ( r#"DELETE FROM _sqlx_migrations WHERE version = ?1"# )
238
236
. bind ( migration. version )
239
- . execute ( self )
237
+ . execute ( & mut tx )
240
238
. await ?;
241
239
240
+ tx. commit ( ) . await ?;
241
+
242
+ let elapsed = start. elapsed ( ) ;
243
+
242
244
Ok ( elapsed)
243
245
} )
244
246
}
You can’t perform that action at this time.
0 commit comments