- 4 表迁移: copilot_rules, copilot_insights, copilot_risk_snapshots, copilot_chat_logs - 4 个 SeaORM Entity 对应新表 - JSONLogic 规则引擎 (evaluate + evaluate_rules) + 5 个单元测试
142 lines
4.8 KiB
Rust
142 lines
4.8 KiB
Rust
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> {
|
|
manager
|
|
.create_table(
|
|
Table::create()
|
|
.table(CopilotInsights::Table)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::Id)
|
|
.uuid()
|
|
.not_null()
|
|
.primary_key(),
|
|
)
|
|
.col(ColumnDef::new(CopilotInsights::TenantId).uuid().not_null())
|
|
.col(ColumnDef::new(CopilotInsights::PatientId).uuid().not_null())
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::InsightType)
|
|
.string_len(50)
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::Source)
|
|
.string_len(20)
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::Severity)
|
|
.string_len(20)
|
|
.null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::Title)
|
|
.string_len(500)
|
|
.not_null(),
|
|
)
|
|
.col(ColumnDef::new(CopilotInsights::Content).json().not_null())
|
|
.col(ColumnDef::new(CopilotInsights::RuleMatches).json().null())
|
|
.col(ColumnDef::new(CopilotInsights::LlmSupplement).text().null())
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::ExpiresAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::IsRead)
|
|
.boolean()
|
|
.not_null()
|
|
.default(false),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::IsDismissed)
|
|
.boolean()
|
|
.not_null()
|
|
.default(false),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::CreatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::UpdatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(ColumnDef::new(CopilotInsights::CreatedBy).uuid().null())
|
|
.col(ColumnDef::new(CopilotInsights::UpdatedBy).uuid().null())
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::DeletedAt)
|
|
.timestamp_with_time_zone()
|
|
.null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(CopilotInsights::VersionLock)
|
|
.integer()
|
|
.not_null()
|
|
.default(1),
|
|
)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_index(
|
|
Index::create()
|
|
.name("idx_copilot_insights_tenant_patient")
|
|
.table(CopilotInsights::Table)
|
|
.col(CopilotInsights::TenantId)
|
|
.col(CopilotInsights::PatientId)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_index(
|
|
Index::create()
|
|
.name("idx_copilot_insights_expires")
|
|
.table(CopilotInsights::Table)
|
|
.col(CopilotInsights::ExpiresAt)
|
|
.to_owned(),
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(CopilotInsights::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
enum CopilotInsights {
|
|
Table,
|
|
Id,
|
|
TenantId,
|
|
PatientId,
|
|
InsightType,
|
|
Source,
|
|
Severity,
|
|
Title,
|
|
Content,
|
|
RuleMatches,
|
|
LlmSupplement,
|
|
ExpiresAt,
|
|
IsRead,
|
|
IsDismissed,
|
|
CreatedAt,
|
|
UpdatedAt,
|
|
CreatedBy,
|
|
UpdatedBy,
|
|
DeletedAt,
|
|
VersionLock,
|
|
}
|