Skip to content

Commit bb6d46a

Browse files
committed
fix: ensure reverse migration progress is not lost for sqlite
See #1966.
1 parent 264637d commit bb6d46a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sqlx-core/src/sqlite/migrate.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,23 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
224224
migration: &'m Migration,
225225
) -> BoxFuture<'m, Result<Duration, MigrateError>> {
226226
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.
227229
let mut tx = self.begin().await?;
228230
let start = Instant::now();
229231

230232
let _ = tx.execute(&*migration.sql).await?;
231233

232-
tx.commit().await?;
233-
234-
let elapsed = start.elapsed();
235-
236234
// language=SQL
237235
let _ = query(r#"DELETE FROM _sqlx_migrations WHERE version = ?1"#)
238236
.bind(migration.version)
239-
.execute(self)
237+
.execute(&mut tx)
240238
.await?;
241239

240+
tx.commit().await?;
241+
242+
let elapsed = start.elapsed();
243+
242244
Ok(elapsed)
243245
})
244246
}

0 commit comments

Comments
 (0)