From 5e314f1d96394af75dd54d4b6aed272e569187b8 Mon Sep 17 00:00:00 2001 From: scx1332 Date: Tue, 16 Jul 2024 14:53:44 +0200 Subject: [PATCH 1/2] f --- .../src/db/connection.rs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/erc20_payment_lib_common/src/db/connection.rs b/crates/erc20_payment_lib_common/src/db/connection.rs index efc682b0..c0f2193e 100644 --- a/crates/erc20_payment_lib_common/src/db/connection.rs +++ b/crates/erc20_payment_lib_common/src/db/connection.rs @@ -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; @@ -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!())?; + if let Err(e) = MIGRATOR.run(&pool).await { + let file_part = if let Some(path) = path { + format!("file {}", path.display()) + } else { + url + }; + return match e { + MigrateError::VersionMissing(_) => { + Err(err_custom_create!( + "Version missing in {file_part}, probably previously run with newer version of application: {e}", + )) + } + _ => { + Err(err_custom_create!( + "Migration error in {file_part}: {e}", + )) + } + }; + } } Ok(pool) From 056d1fc1949ebd4db55a97e0e9b45235c9ac09f6 Mon Sep 17 00:00:00 2001 From: scx1332 Date: Tue, 16 Jul 2024 14:58:58 +0200 Subject: [PATCH 2/2] f --- .../src/db/connection.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/erc20_payment_lib_common/src/db/connection.rs b/crates/erc20_payment_lib_common/src/db/connection.rs index c0f2193e..411af807 100644 --- a/crates/erc20_payment_lib_common/src/db/connection.rs +++ b/crates/erc20_payment_lib_common/src/db/connection.rs @@ -54,25 +54,25 @@ pub async fn create_sqlite_connection( .map_err(err_from!())?; if run_migrations { - if let Err(e) = MIGRATOR.run(&pool).await { + MIGRATOR.run(&pool).await.map_err(|e| { let file_part = if let Some(path) = path { format!("file {}", path.display()) } else { url }; - return match e { + match e { MigrateError::VersionMissing(_) => { - Err(err_custom_create!( - "Version missing in {file_part}, probably previously run with newer version of application: {e}", - )) + err_custom_create!( + "Error during migration in {file_part}, probably previously run with newer version of application: {e}", + ) } _ => { - Err(err_custom_create!( + err_custom_create!( "Migration error in {file_part}: {e}", - )) + ) } - }; - } + } + })? } Ok(pool)