feat(ai): 知识库 V2 菜单迁移 + 文本切片器 + 前端路由权限
- 新增迁移 000168:在 AI 知识库同级添加「知识库 V2」菜单,绑定 admin 角色 - 新增 document/chunker.rs:固定大小 + overlap 文本切片器(5 单元测试) - 前端 routeConfig 添加 /health/ai-knowledge-v2 权限声明 - App.tsx validateRouteCoverage 补充 v2 路径
This commit is contained in:
@@ -174,6 +174,7 @@ mod m20260526_000164_ai_prompt_add_analysis_type;
|
||||
mod m20260526_000165_ai_prompt_fix_analysis_type;
|
||||
mod m20260526_000166_create_ai_knowledge_bases;
|
||||
mod m20260526_000167_create_ai_knowledge_documents;
|
||||
mod m20260527_000168_ai_knowledge_v2_menu;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -355,6 +356,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260526_000165_ai_prompt_fix_analysis_type::Migration),
|
||||
Box::new(m20260526_000166_create_ai_knowledge_bases::Migration),
|
||||
Box::new(m20260526_000167_create_ai_knowledge_documents::Migration),
|
||||
Box::new(m20260527_000168_ai_knowledge_v2_menu::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// 在"AI 知识库"同级位置添加"知识库 V2"菜单
|
||||
// parent_id 取旧 ai-knowledge 菜单的 parent_id
|
||||
let sql = r#"
|
||||
INSERT INTO sys_menu (id, parent_id, name, path, icon, sort, permission, component, is_external, is_cached, status, visible, created_at, updated_at, deleted_at)
|
||||
SELECT
|
||||
gen_random_uuid(),
|
||||
parent_id,
|
||||
'知识库 V2',
|
||||
'/health/ai-knowledge-v2',
|
||||
'DatabaseOutlined',
|
||||
54,
|
||||
'ai.knowledge.list',
|
||||
'ai/KnowledgeV2Page',
|
||||
false,
|
||||
false,
|
||||
'active',
|
||||
true,
|
||||
now(),
|
||||
now(),
|
||||
NULL
|
||||
FROM sys_menu
|
||||
WHERE path = '/health/ai-knowledge' AND deleted_at IS NULL
|
||||
LIMIT 1
|
||||
ON CONFLICT DO NOTHING
|
||||
"#;
|
||||
|
||||
manager.get_connection().execute_unprepared(sql).await?;
|
||||
|
||||
// 绑定到 admin 角色
|
||||
let role_sql = r#"
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
SELECT r.id, m.id
|
||||
FROM sys_role r, sys_menu m
|
||||
WHERE r.code = 'admin' AND r.deleted_at IS NULL
|
||||
AND m.path = '/health/ai-knowledge-v2' AND m.deleted_at IS NULL
|
||||
ON CONFLICT DO NOTHING
|
||||
"#;
|
||||
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared(role_sql)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared("DELETE FROM sys_menu WHERE path = '/health/ai-knowledge-v2'")
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user