Skip to content

Commit

Permalink
More informative error when migration problem occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Jul 16, 2024
1 parent 4904582 commit 4f6b14a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions crates/erc20_payment_lib_common/src/db/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::PaymentError;
use crate::error::*;
use crate::{err_custom_create, err_from};
use sqlx::migrate::Migrator;
use sqlx::migrate::{MigrateError, Migrator};
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::SqlitePool;
use std::env;
Expand Down Expand Up @@ -54,7 +54,25 @@ pub async fn create_sqlite_connection(
.map_err(err_from!())?;

if run_migrations {
MIGRATOR.run(&pool).await.map_err(err_from!())?;
MIGRATOR.run(&pool).await.map_err(|e| {
let file_part = if let Some(path) = path {
format!("file {}", path.display())
} else {
url
};
match e {
MigrateError::VersionMissing(_) => {
err_custom_create!(
"Error during migration in {file_part}, probably previously run with newer version of application: {e}",
)
}
_ => {
err_custom_create!(
"Migration error in {file_part}: {e}",
)
}
}
})?
}

Ok(pool)
Expand Down

0 comments on commit 4f6b14a

Please sign in to comment.