diff --git a/sqlx-core/src/migrate/error.rs b/sqlx-core/src/migrate/error.rs index fb5e09e9af..608d55b18d 100644 --- a/sqlx-core/src/migrate/error.rs +++ b/sqlx-core/src/migrate/error.rs @@ -6,6 +6,9 @@ pub enum MigrateError { #[error("while executing migrations: {0}")] Execute(#[from] Error), + #[error("while executing migration {1}: {0}")] + ExecuteMigration(#[source] Error, i64), + #[error("while resolving migrations: {0}")] Source(#[source] BoxDynError), diff --git a/sqlx-mysql/src/migrate.rs b/sqlx-mysql/src/migrate.rs index dac2753e5f..7c514d8631 100644 --- a/sqlx-mysql/src/migrate.rs +++ b/sqlx-mysql/src/migrate.rs @@ -199,7 +199,10 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations ( .execute(&mut *tx) .await?; - let _ = tx.execute(&*migration.sql).await?; + let _ = tx + .execute(&*migration.sql) + .await + .map_err(|e| MigrateError::ExecuteMigration(e, migration.version))?; // language=MySQL let _ = query( diff --git a/sqlx-postgres/src/migrate.rs b/sqlx-postgres/src/migrate.rs index fdd2dd6fe3..fe45404c5f 100644 --- a/sqlx-postgres/src/migrate.rs +++ b/sqlx-postgres/src/migrate.rs @@ -216,7 +216,10 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations ( // The `execution_time` however can only be measured for the whole transaction. This value _only_ exists for // data lineage and debugging reasons, so it is not super important if it is lost. So we initialize it to -1 // and update it once the actual transaction completed. - let _ = tx.execute(&*migration.sql).await?; + let _ = tx + .execute(&*migration.sql) + .await + .map_err(|e| MigrateError::ExecuteMigration(e, migration.version))?; // language=SQL let _ = query( diff --git a/sqlx-sqlite/src/migrate.rs b/sqlx-sqlite/src/migrate.rs index 94a39a94f0..fea74bf752 100644 --- a/sqlx-sqlite/src/migrate.rs +++ b/sqlx-sqlite/src/migrate.rs @@ -142,7 +142,10 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations ( // The `execution_time` however can only be measured for the whole transaction. This value _only_ exists for // data lineage and debugging reasons, so it is not super important if it is lost. So we initialize it to -1 // and update it once the actual transaction completed. - let _ = tx.execute(&*migration.sql).await?; + let _ = tx + .execute(&*migration.sql) + .await + .map_err(|e| MigrateError::ExecuteMigration(e, migration.version))?; // language=SQL let _ = query(