Skip to content

Commit 45b5b61

Browse files
authored
Add version information for failed cli migration (#3129) (#3130)
1 parent 0aae849 commit 45b5b61

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

sqlx-core/src/migrate/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ pub enum MigrateError {
66
#[error("while executing migrations: {0}")]
77
Execute(#[from] Error),
88

9+
#[error("while executing migration {1}: {0}")]
10+
ExecuteMigration(#[source] Error, i64),
11+
912
#[error("while resolving migrations: {0}")]
1013
Source(#[source] BoxDynError),
1114

sqlx-mysql/src/migrate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
199199
.execute(&mut *tx)
200200
.await?;
201201

202-
let _ = tx.execute(&*migration.sql).await?;
202+
let _ = tx
203+
.execute(&*migration.sql)
204+
.await
205+
.map_err(|e| MigrateError::ExecuteMigration(e, migration.version))?;
203206

204207
// language=MySQL
205208
let _ = query(

sqlx-postgres/src/migrate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
216216
// The `execution_time` however can only be measured for the whole transaction. This value _only_ exists for
217217
// data lineage and debugging reasons, so it is not super important if it is lost. So we initialize it to -1
218218
// and update it once the actual transaction completed.
219-
let _ = tx.execute(&*migration.sql).await?;
219+
let _ = tx
220+
.execute(&*migration.sql)
221+
.await
222+
.map_err(|e| MigrateError::ExecuteMigration(e, migration.version))?;
220223

221224
// language=SQL
222225
let _ = query(

sqlx-sqlite/src/migrate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
142142
// The `execution_time` however can only be measured for the whole transaction. This value _only_ exists for
143143
// data lineage and debugging reasons, so it is not super important if it is lost. So we initialize it to -1
144144
// and update it once the actual transaction completed.
145-
let _ = tx.execute(&*migration.sql).await?;
145+
let _ = tx
146+
.execute(&*migration.sql)
147+
.await
148+
.map_err(|e| MigrateError::ExecuteMigration(e, migration.version))?;
146149

147150
// language=SQL
148151
let _ = query(

0 commit comments

Comments
 (0)