From a97e278fc698096baf5cfd4938e35dd91c5d102a Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 14 Oct 2024 16:17:07 +0800 Subject: [PATCH 1/6] fix(sql): more friendly panic message when no migrations providing --- plugins/sql/src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/sql/src/lib.rs b/plugins/sql/src/lib.rs index ec9362bff1..39c1869892 100644 --- a/plugins/sql/src/lib.rs +++ b/plugins/sql/src/lib.rs @@ -144,10 +144,15 @@ impl Builder { for db in config.preload { let pool = DbPool::connect(&db, app).await?; - - if let Some(migrations) = self.migrations.as_mut().unwrap().remove(&db) { - let migrator = Migrator::new(migrations).await?; + + if let Some(migration_map) = self.migrations.as_mut(){ + if let Some(migrations)= migration_map.remove(&db){ + let migrator = Migrator::new(migrations).await?; pool.migrate(&migrator).await?; + } + } + else{ + panic!("No migrations providing. Please provide at least one migration or clear `preload` list"); } lock.insert(db, pool); From e8806984eb5a2296ed0fe93765946902d998ecae Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 14 Oct 2024 16:20:18 +0800 Subject: [PATCH 2/6] refactor(sql): cargo clippy & cargo fmt --- plugins/sql/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/sql/src/lib.rs b/plugins/sql/src/lib.rs index 39c1869892..48054b271b 100644 --- a/plugins/sql/src/lib.rs +++ b/plugins/sql/src/lib.rs @@ -144,11 +144,11 @@ impl Builder { for db in config.preload { let pool = DbPool::connect(&db, app).await?; - + if let Some(migration_map) = self.migrations.as_mut(){ if let Some(migrations)= migration_map.remove(&db){ let migrator = Migrator::new(migrations).await?; - pool.migrate(&migrator).await?; + pool.migrate(&migrator).await?; } } else{ From 20027d969f70967d1f07afc4a0c761133677a4c5 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 14 Oct 2024 16:56:09 +0800 Subject: [PATCH 3/6] doc(sql): adding extra notice message on *Applying Migrations* section --- plugins/sql/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/sql/README.md b/plugins/sql/README.md index 85318cfff8..110a33a0fd 100644 --- a/plugins/sql/README.md +++ b/plugins/sql/README.md @@ -168,6 +168,8 @@ fn main() { To apply the migrations when the plugin is initialized, add the connection string to the `tauri.conf.json` file: +> Notice: if no migration provided, keeping the `preload` empty + ```json { "plugins": { From 002b7a252e6e61d50239553d45bde1a89ffc9dca Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 14 Oct 2024 16:58:43 +0800 Subject: [PATCH 4/6] doc(sql): adding extra notice message on *Applying Migrations* section --- plugins/sql/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sql/README.md b/plugins/sql/README.md index 110a33a0fd..35447054aa 100644 --- a/plugins/sql/README.md +++ b/plugins/sql/README.md @@ -168,7 +168,7 @@ fn main() { To apply the migrations when the plugin is initialized, add the connection string to the `tauri.conf.json` file: -> Notice: if no migration provided, keeping the `preload` empty +> Notice: If `migration` is not provided, make sure that `preload` is kept empty ```json { From 14892747ec8ffd9332abdab9c61d4f14995ee7f0 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Mon, 14 Oct 2024 22:36:46 +0800 Subject: [PATCH 5/6] refactor(sql): ignore migration miss --- plugins/sql/README.md | 1 - plugins/sql/src/lib.rs | 13 +++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/sql/README.md b/plugins/sql/README.md index 35447054aa..07cd168679 100644 --- a/plugins/sql/README.md +++ b/plugins/sql/README.md @@ -168,7 +168,6 @@ fn main() { To apply the migrations when the plugin is initialized, add the connection string to the `tauri.conf.json` file: -> Notice: If `migration` is not provided, make sure that `preload` is kept empty ```json { diff --git a/plugins/sql/src/lib.rs b/plugins/sql/src/lib.rs index 48054b271b..f66137b8e3 100644 --- a/plugins/sql/src/lib.rs +++ b/plugins/sql/src/lib.rs @@ -145,14 +145,11 @@ impl Builder { for db in config.preload { let pool = DbPool::connect(&db, app).await?; - if let Some(migration_map) = self.migrations.as_mut(){ - if let Some(migrations)= migration_map.remove(&db){ - let migrator = Migrator::new(migrations).await?; - pool.migrate(&migrator).await?; - } - } - else{ - panic!("No migrations providing. Please provide at least one migration or clear `preload` list"); + if let Some(migrations) = + self.migrations.as_mut().and_then(|mm| mm.remove(&db)) + { + let migrator = Migrator::new(migrations).await?; + pool.migrate(&migrator).await?; } lock.insert(db, pool); From f440508181894e13b09617905e0b01a73f1d7578 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Mon, 14 Oct 2024 22:42:10 +0800 Subject: [PATCH 6/6] fix(SQL): fix readme.md format --- plugins/sql/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/sql/README.md b/plugins/sql/README.md index 07cd168679..85318cfff8 100644 --- a/plugins/sql/README.md +++ b/plugins/sql/README.md @@ -168,7 +168,6 @@ fn main() { To apply the migrations when the plugin is initialized, add the connection string to the `tauri.conf.json` file: - ```json { "plugins": {