Files
hms/crates/erp-server/migration/src/m20260429_000092_device_readings_metric.rs

49 lines
1.4 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
.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
}
}