//! 补充 warning 级别危急值阈值种子数据 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(); let result = db .query_one(sea_orm::Statement::from_string( sea_orm::DatabaseBackend::Postgres, "SELECT id::text FROM tenant LIMIT 1".to_string(), )) .await?; let tid = match result { Some(row) => row.try_get_by_index::(0).unwrap_or_default(), None => return Ok(()), }; // warning 级别阈值 — 用于小程序体征参考范围 let sql = format!( r#" INSERT INTO critical_value_threshold (id, tenant_id, indicator, direction, threshold_value, level, is_active, created_at, updated_at) VALUES (gen_random_uuid(), '{tid}', 'systolic_bp', 'high', 140, 'warning', true, now(), now()), (gen_random_uuid(), '{tid}', 'diastolic_bp', 'high', 90, 'warning', true, now(), now()), (gen_random_uuid(), '{tid}', 'heart_rate', 'high', 100, 'warning', true, now(), now()), (gen_random_uuid(), '{tid}', 'heart_rate', 'low', 60, 'warning', true, now(), now()), (gen_random_uuid(), '{tid}', 'blood_sugar_fasting', 'high', 6.1, 'warning', true, now(), now()), (gen_random_uuid(), '{tid}', 'blood_sugar_postprandial','high', 7.8, 'warning', true, now(), now()) "# ); db.execute(sea_orm::Statement::from_string( sea_orm::DatabaseBackend::Postgres, sql, )) .await?; Ok(()) } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { let db = manager.get_connection(); db.execute(sea_orm::Statement::from_string( sea_orm::DatabaseBackend::Postgres, "DELETE FROM critical_value_threshold WHERE level = 'warning'".to_string(), )) .await?; Ok(()) } }