diff --git a/apps/desktop/src-tauri/src/business/services/material_service.rs b/apps/desktop/src-tauri/src/business/services/material_service.rs index eda5792..888f588 100644 --- a/apps/desktop/src-tauri/src/business/services/material_service.rs +++ b/apps/desktop/src-tauri/src/business/services/material_service.rs @@ -133,6 +133,9 @@ impl MaterialService { // 确定素材类型 let material_type = MaterialType::from_extension(extension); + // 添加调试日志 + println!("Creating material with model_id: {:?}", model_id); + // 创建素材对象(带模特绑定) let material = Material::new_with_model( project_id.to_string(), diff --git a/apps/desktop/src-tauri/src/data/repositories/material_repository.rs b/apps/desktop/src-tauri/src/data/repositories/material_repository.rs index 7646247..970f1a0 100644 --- a/apps/desktop/src-tauri/src/data/repositories/material_repository.rs +++ b/apps/desktop/src-tauri/src/data/repositories/material_repository.rs @@ -26,7 +26,10 @@ impl MaterialRepository { /// 创建素材 pub fn create(&self, material: &Material) -> Result<()> { let conn = self.connection.lock().unwrap(); - + + // 添加调试日志 + println!("Creating material with model_id: {:?}", material.model_id); + let metadata_json = serde_json::to_string(&material.metadata)?; let scene_detection_json = material.scene_detection.as_ref() .map(|sd| serde_json::to_string(sd)) diff --git a/apps/desktop/src-tauri/src/infrastructure/database.rs b/apps/desktop/src-tauri/src/infrastructure/database.rs index bbda94b..ce669f3 100644 --- a/apps/desktop/src-tauri/src/infrastructure/database.rs +++ b/apps/desktop/src-tauri/src/infrastructure/database.rs @@ -114,6 +114,7 @@ impl Database { "CREATE TABLE IF NOT EXISTS materials ( id TEXT PRIMARY KEY, project_id TEXT NOT NULL, + model_id TEXT, name TEXT NOT NULL, original_path TEXT NOT NULL, file_size INTEGER NOT NULL, @@ -402,6 +403,11 @@ impl Database { [], )?; + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_materials_model_id ON materials (model_id)", + [], + )?; + // 创建模板表索引 conn.execute( "CREATE INDEX IF NOT EXISTS idx_templates_import_status ON templates (import_status)", @@ -875,18 +881,29 @@ impl Database { let has_model_id_column = conn.prepare("SELECT model_id FROM materials LIMIT 1").is_ok(); if !has_model_id_column { println!("Adding model_id column to materials table"); - conn.execute( + match conn.execute( "ALTER TABLE materials ADD COLUMN model_id TEXT", [], - )?; + ) { + Ok(_) => { + println!("Successfully added model_id column to materials table"); - // 创建模特关联索引 - conn.execute( - "CREATE INDEX IF NOT EXISTS idx_materials_model_id ON materials (model_id)", - [], - )?; - - println!("Added model_id column and index to materials table"); + // 创建模特关联索引 + match conn.execute( + "CREATE INDEX IF NOT EXISTS idx_materials_model_id ON materials (model_id)", + [], + ) { + Ok(_) => println!("Successfully created index on model_id column"), + Err(e) => println!("Warning: Failed to create index on model_id column: {}", e), + } + } + Err(e) => { + println!("Error adding model_id column to materials table: {}", e); + return Err(e.into()); + } + } + } else { + println!("model_id column already exists in materials table"); } // 添加片段匹配规则字段到轨道片段表 diff --git a/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs b/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs index 8af2c35..f47a4c5 100644 --- a/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs +++ b/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs @@ -42,6 +42,8 @@ pub async fn import_materials_async( request: CreateMaterialRequest, app_handle: tauri::AppHandle, ) -> Result { + // 添加调试日志 + println!("Import request received with model_id: {:?}", request.model_id); // 获取数据库连接,避免持有MutexGuard let connection = { let repository_guard = state.get_material_repository()