use sea_orm_migration::{prelude::*, schema::*}; #[derive(DeriveMigrationName)] pub struct Migration; #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .create_table( Table::create() .table(Alias::new("diagnosis")) .if_not_exists() .col(uuid("id").primary_key()) .col(uuid("tenant_id").not_null()) .col(uuid("patient_id").not_null()) .col(uuid_null("health_record_id")) .col(string_uniq("icd_code").not_null()) .col(string("diagnosis_name").not_null()) .col(string("diagnosis_type").not_null().default("primary")) .col(date("diagnosed_date").not_null()) .col(string("status").not_null().default("active")) .col(uuid_null("diagnosed_by")) .col(string_null("notes")) .col(timestamp_with_time_zone("created_at").not_null().default(Expr::current_timestamp())) .col(timestamp_with_time_zone("updated_at").not_null().default(Expr::current_timestamp())) .col(uuid_null("created_by")) .col(uuid_null("updated_by")) .col(timestamp_with_time_zone_null("deleted_at")) .col(integer("version").not_null().default(1)) .to_owned(), ) .await?; manager .create_index( Index::create() .if_not_exists() .name("idx_diagnosis_tenant_patient") .table(Alias::new("diagnosis")) .col(Alias::new("tenant_id")) .col(Alias::new("patient_id")) .to_owned(), ) .await?; manager .create_index( Index::create() .if_not_exists() .name("idx_diagnosis_icd_code") .table(Alias::new("diagnosis")) .col(Alias::new("tenant_id")) .col(Alias::new("icd_code")) .to_owned(), ) .await?; manager .create_index( Index::create() .if_not_exists() .name("idx_diagnosis_deleted_at") .table(Alias::new("diagnosis")) .col(Alias::new("deleted_at")) .to_owned(), ) .await?; Ok(()) } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(Alias::new("diagnosis")).to_owned()) .await } }