P0: consultation handler sender_role 从请求体移除,改为服务端推导(防伪造) P1: 所有软删除操作统一使用 check_version 乐观锁(6个函数) P1: 修复 health_trend 索引缺少 tenant_id 前导列 + follow_up_record 补 (tenant_id, executed_date) 索引 P2: Decimal->f64 使用 ToPrimitive::to_f64 替代脆弱的 to_string().parse() P2: 预约取消释放槽位+状态更新包裹进同一事务
50 lines
1.5 KiB
Rust
50 lines
1.5 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> {
|
|
let db = manager.get_connection();
|
|
|
|
// 删除旧索引(缺少 tenant_id 前导列)
|
|
db.execute_unprepared(
|
|
"DROP INDEX IF EXISTS idx_health_trend_patient_period"
|
|
).await?;
|
|
|
|
// 重建为包含 tenant_id 的正确索引
|
|
db.execute_unprepared(
|
|
"CREATE INDEX IF NOT EXISTS idx_health_trend_tenant_patient_period \
|
|
ON health_trend (tenant_id, patient_id, period_start DESC)"
|
|
).await?;
|
|
|
|
// 添加 follow_up_record 缺失的 (tenant_id, executed_date) 索引
|
|
db.execute_unprepared(
|
|
"CREATE INDEX IF NOT EXISTS idx_follow_up_record_tenant_executed_date \
|
|
ON follow_up_record (tenant_id, executed_date DESC)"
|
|
).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
let db = manager.get_connection();
|
|
|
|
db.execute_unprepared(
|
|
"DROP INDEX IF EXISTS idx_health_trend_tenant_patient_period"
|
|
).await?;
|
|
|
|
db.execute_unprepared(
|
|
"DROP INDEX IF EXISTS idx_follow_up_record_tenant_executed_date"
|
|
).await?;
|
|
|
|
db.execute_unprepared(
|
|
"CREATE INDEX IF NOT EXISTS idx_health_trend_patient_period \
|
|
ON health_trend (patient_id, period_start)"
|
|
).await?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|