feat(health): patient_devices 增强 — status/firmware/manufacturer/connection_type/metadata
- 新增迁移:添加 status/firmware_version/manufacturer/connection_type/metadata 列 - 更新 Entity:新增对应字段(含默认值) - 修复 device_reading_service 自动绑定设备时填充新字段
This commit is contained in:
@@ -26,6 +26,14 @@ pub struct Model {
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version: i32,
|
||||
pub status: String,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub firmware_version: Option<String>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub manufacturer: Option<String>,
|
||||
pub connection_type: String,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
||||
@@ -187,6 +187,11 @@ async fn ensure_device_binding(
|
||||
updated_by: Set(None),
|
||||
deleted_at: Set(None),
|
||||
version: Set(1),
|
||||
status: Set("active".to_string()),
|
||||
firmware_version: Set(None),
|
||||
manufacturer: Set(None),
|
||||
connection_type: Set("ble".to_string()),
|
||||
metadata: Set(None),
|
||||
};
|
||||
binding.insert(db).await?;
|
||||
} else if let Some(existing) = existing {
|
||||
|
||||
@@ -104,6 +104,8 @@ mod m20260502_000101_seed_health_dictionaries;
|
||||
mod m20260502_000102_seed_warning_thresholds;
|
||||
mod m20260502_000103_seed_follow_up_template_menu;
|
||||
mod m20260504_000104_create_vital_signs_daily;
|
||||
mod m20260504_000105_alter_patient_devices_add_status;
|
||||
mod m20260504_000106_create_api_clients;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -215,6 +217,8 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260502_000102_seed_warning_thresholds::Migration),
|
||||
Box::new(m20260502_000103_seed_follow_up_template_menu::Migration),
|
||||
Box::new(m20260504_000104_create_vital_signs_daily::Migration),
|
||||
Box::new(m20260504_000105_alter_patient_devices_add_status::Migration),
|
||||
Box::new(m20260504_000106_create_api_clients::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
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
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("patient_devices"))
|
||||
.add_column(
|
||||
ColumnDef::new(Alias::new("status"))
|
||||
.string()
|
||||
.not_null()
|
||||
.default("active"),
|
||||
)
|
||||
.add_column(ColumnDef::new(Alias::new("firmware_version")).string())
|
||||
.add_column(ColumnDef::new(Alias::new("manufacturer")).string())
|
||||
.add_column(
|
||||
ColumnDef::new(Alias::new("connection_type"))
|
||||
.string()
|
||||
.not_null()
|
||||
.default("ble"),
|
||||
)
|
||||
.add_column(ColumnDef::new(Alias::new("metadata")).json_binary())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("patient_devices"))
|
||||
.drop_column(Alias::new("status"))
|
||||
.drop_column(Alias::new("firmware_version"))
|
||||
.drop_column(Alias::new("manufacturer"))
|
||||
.drop_column(Alias::new("connection_type"))
|
||||
.drop_column(Alias::new("metadata"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user