Kaynağa Gözat

Changes

1. Fix migration to avoid re-running migration twice
2. Remove tokio dependency
Cesar Rodas 2 ay önce
ebeveyn
işleme
1f85d0fd7a

+ 0 - 1
crates/cdk-sql-common/Cargo.toml

@@ -22,7 +22,6 @@ async-trait.workspace = true
 cdk-common = { workspace = true, features = ["test"] }
 bitcoin.workspace = true
 thiserror.workspace = true
-tokio.workspace = true
 tracing.workspace = true
 serde.workspace = true
 serde_json.workspace = true

+ 6 - 3
crates/cdk-sql-common/src/common.rs

@@ -21,14 +21,17 @@ pub async fn migrate<C: DatabaseExecutor>(
 
     // Apply each migration if it hasn’t been applied yet
     for (name, sql) in migrations {
-        if let Some((prefix, _)) = name.split_once(['/', '\\']) {
+        let basename = if let Some((prefix, basename)) = name.split_once(['/', '\\']) {
             if prefix != db_prefix {
                 continue;
             }
-        }
+            basename
+        } else {
+            name
+        };
 
         let is_missing = query("SELECT name FROM migrations WHERE name = :name")?
-            .bind("name", name)
+            .bind("name", basename)
             .pluck(conn)
             .await?
             .is_none();