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] 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 35447054..07cd1686 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 48054b27..f66137b8 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);