feat(db): device_readings 新增 metric 字段用于多行拆分存储
This commit is contained in:
@@ -91,6 +91,7 @@ mod m20260428_000088_rls_policy_strict;
|
||||
mod m20260428_000089_blind_indexes;
|
||||
mod m20260428_000090_critical_alerts;
|
||||
mod m20260428_000091_dead_letter_events;
|
||||
mod m20260429_000092_device_readings_metric;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -189,6 +190,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260428_000089_blind_indexes::Migration),
|
||||
Box::new(m20260428_000090_critical_alerts::Migration),
|
||||
Box::new(m20260428_000091_dead_letter_events::Migration),
|
||||
Box::new(m20260429_000092_device_readings_metric::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
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("device_readings"))
|
||||
.add_column(ColumnDef::new(Alias::new("metric")).string().null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_dr_metric")
|
||||
.table(Alias::new("device_readings"))
|
||||
.col(Alias::new("tenant_id"))
|
||||
.col(Alias::new("patient_id"))
|
||||
.col(Alias::new("metric"))
|
||||
.col(Alias::new("measured_at"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_index(Index::drop().name("idx_dr_metric").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("device_readings"))
|
||||
.drop_column(Alias::new("metric"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user