Skip to content

Commit d3818f2

Browse files
committed
Adjusted error handling to new error type
1 parent f1a3f87 commit d3818f2

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/migrate/apply.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rorm_db::sql::drop_table::DropTable;
77
use rorm_db::sql::insert::Insert;
88
use rorm_db::sql::value::Value;
99
use rorm_db::sql::DBImpl;
10-
use rorm_db::transaction::Transaction;
10+
use rorm_db::transaction::{Transaction, TransactionError};
1111
use rorm_db::Database;
1212
use rorm_declaration::migration::{Migration, Operation};
1313
use thiserror::Error;
@@ -59,8 +59,11 @@ pub async fn apply_migration(
5959
location: ApplyMigrationErrorLocation::UpdateLastMigration,
6060
})?;
6161

62-
tx.commit().await.map_err(|error| ApplyMigrationError {
63-
error,
62+
tx.commit().await.map_err(|x| ApplyMigrationError {
63+
error: match x {
64+
TransactionError::Database(x) => x,
65+
TransactionError::Hook(_) => unreachable!("rorm-cli does not use hooks"),
66+
},
6467
location: ApplyMigrationErrorLocation::CommitTransaction,
6568
})?;
6669

src/migrate/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::Path;
44
use anyhow::{anyhow, Context};
55
use rorm_db::executor::{Executor, Nothing, Optional};
66
use rorm_db::sql::create_table::CreateTable;
7+
use rorm_db::transaction::TransactionError;
78
use rorm_db::Database;
89
use rorm_declaration::config::DatabaseConfig;
910
use rorm_declaration::imr::{Annotation, DbType};
@@ -101,6 +102,10 @@ pub async fn run_migrate_custom(
101102

102103
tx.commit()
103104
.await
105+
.map_err(|x| match x {
106+
TransactionError::Database(x) => x,
107+
TransactionError::Hook(_) => unreachable!("rorm-cli does not use hooks"),
108+
})
104109
.with_context(|| "Couldn't create internal last migration table")?;
105110

106111
let last_migration: Option<i32> = pool

0 commit comments

Comments
 (0)