feat(db): 创建 ai_knowledge_bases 表迁移
知识库 V2 第一张表:支持多类型知识库(规则/参考资料/临床指南/FAQ), 含意图关键词 JSONB、切片策略 JSONB、文档/切片计数器。
This commit is contained in:
@@ -172,6 +172,7 @@ mod m20260522_000162_seed_patient_miniprogram_permissions;
|
||||
mod m20260526_000163_points_rule_unique_event_type;
|
||||
mod m20260526_000164_ai_prompt_add_analysis_type;
|
||||
mod m20260526_000165_ai_prompt_fix_analysis_type;
|
||||
mod m20260526_000166_create_ai_knowledge_bases;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -351,6 +352,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260526_000163_points_rule_unique_event_type::Migration),
|
||||
Box::new(m20260526_000164_ai_prompt_add_analysis_type::Migration),
|
||||
Box::new(m20260526_000165_ai_prompt_fix_analysis_type::Migration),
|
||||
Box::new(m20260526_000166_create_ai_knowledge_bases::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(Iden)]
|
||||
enum AiKnowledgeBases {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
Name,
|
||||
KbType,
|
||||
Description,
|
||||
Icon,
|
||||
ChunkStrategy,
|
||||
IntentKeywords,
|
||||
EmbeddingModel,
|
||||
IsEnabled,
|
||||
DocumentCount,
|
||||
ChunkCount,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
VersionLock,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(AiKnowledgeBases::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(AiKnowledgeBases::TenantId).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::Name)
|
||||
.string_len(200)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::KbType)
|
||||
.string_len(50)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(AiKnowledgeBases::Description).text())
|
||||
.col(ColumnDef::new(AiKnowledgeBases::Icon).string_len(50))
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::ChunkStrategy)
|
||||
.json_binary()
|
||||
.not_null()
|
||||
.default(Expr::cust("'{}'")),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::IntentKeywords)
|
||||
.json_binary()
|
||||
.not_null()
|
||||
.default(Expr::cust("'[]'")),
|
||||
)
|
||||
.col(ColumnDef::new(AiKnowledgeBases::EmbeddingModel).string_len(100))
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::IsEnabled)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(true),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::DocumentCount)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::ChunkCount)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(AiKnowledgeBases::CreatedBy).uuid())
|
||||
.col(ColumnDef::new(AiKnowledgeBases::UpdatedBy).uuid())
|
||||
.col(ColumnDef::new(AiKnowledgeBases::DeletedAt).timestamp_with_time_zone())
|
||||
.col(
|
||||
ColumnDef::new(AiKnowledgeBases::VersionLock)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.if_not_exists()
|
||||
.name("idx_kb_tenant")
|
||||
.table(AiKnowledgeBases::Table)
|
||||
.col(AiKnowledgeBases::TenantId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.if_not_exists()
|
||||
.name("idx_kb_type")
|
||||
.table(AiKnowledgeBases::Table)
|
||||
.col(AiKnowledgeBases::TenantId)
|
||||
.col(AiKnowledgeBases::KbType)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(AiKnowledgeBases::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user