diff --git a/apps/desktop/src-tauri/src/app_state.rs b/apps/desktop/src-tauri/src/app_state.rs index 0ae5b77..1055a2a 100644 --- a/apps/desktop/src-tauri/src/app_state.rs +++ b/apps/desktop/src-tauri/src/app_state.rs @@ -520,12 +520,11 @@ impl AppState { // 获取配置管理器 let config_manager = self.get_config_manager().await?; - // 获取数据库路径 + // 获取数据库实例 let database = self.get_database(); - let db_path = database.get_db_path().unwrap_or_else(|| "mixvideo.db".to_string()); // 创建服务管理器 - let service_manager = Arc::new(ServiceManager::new(config_manager.as_ref().clone(), db_path)); + let service_manager = Arc::new(ServiceManager::new(config_manager.as_ref().clone(), database)); // 初始化服务管理器 service_manager.initialize().await?; diff --git a/apps/desktop/src-tauri/src/business/services/service_manager.rs b/apps/desktop/src-tauri/src/business/services/service_manager.rs index 67e5e13..558abb0 100644 --- a/apps/desktop/src-tauri/src/business/services/service_manager.rs +++ b/apps/desktop/src-tauri/src/business/services/service_manager.rs @@ -40,8 +40,8 @@ pub struct ServiceManager { impl ServiceManager { /// 创建新的服务管理器 - pub fn new(config_manager: ConfigManager, db_path: String) -> Self { - let repository = Arc::new(ComfyUIRepository::new(db_path)); + pub fn new(config_manager: ConfigManager, database: Arc) -> Self { + let repository = Arc::new(ComfyUIRepository::new(database)); Self { comfyui_manager: Arc::new(RwLock::new(None)), diff --git a/apps/desktop/src-tauri/src/data/repositories/comfyui_repository.rs b/apps/desktop/src-tauri/src/data/repositories/comfyui_repository.rs index 059ee89..2bc90cc 100644 --- a/apps/desktop/src-tauri/src/data/repositories/comfyui_repository.rs +++ b/apps/desktop/src-tauri/src/data/repositories/comfyui_repository.rs @@ -5,6 +5,7 @@ use anyhow::{Result, anyhow}; use rusqlite::{Connection, params, Row}; use serde_json; use std::collections::HashMap; +use std::sync::Arc; use tracing::{info, warn, error, debug}; use crate::data::models::comfyui::{ @@ -14,32 +15,27 @@ use crate::data::models::comfyui::{ /// ComfyUI 数据仓库 pub struct ComfyUIRepository { - db_path: String, + database: Arc, } impl ComfyUIRepository { /// 创建新的数据仓库实例 - pub fn new(db_path: String) -> Self { - Self { db_path } + pub fn new(database: Arc) -> Self { + Self { database } } /// 获取数据库连接 - fn get_connection(&self) -> Result { - let conn = Connection::open(&self.db_path)?; - // 启用外键约束 - conn.execute("PRAGMA foreign_keys = ON", [])?; - Ok(conn) + fn get_connection(&self) -> Result> { + let conn = self.database.get_connection(); + conn.lock().map_err(|e| anyhow!("获取数据库连接失败: {}", e)) } - /// 初始化数据库表 + /// 初始化数据库表(现在通过主数据库的migration系统处理) pub fn initialize(&self) -> Result<()> { - let conn = self.get_connection()?; - - // 读取并执行迁移脚本 - let migration_sql = include_str!("../migrations/comfyui_tables.sql"); - conn.execute_batch(migration_sql)?; - - info!("ComfyUI 数据库表初始化完成"); + // ComfyUI表现在通过主数据库的migration系统创建 + // 这里只需要确保连接可用 + let _conn = self.get_connection()?; + info!("ComfyUI 数据仓库初始化完成"); Ok(()) }