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 .create_table( Table::create() .table(Consent::Table) .col( ColumnDef::new(Consent::Id) .uuid() .not_null() .primary_key(), ) .col(ColumnDef::new(Consent::TenantId).uuid().not_null()) .col(ColumnDef::new(Consent::PatientId).uuid().not_null()) .col(ColumnDef::new(Consent::ConsentType).string_len(50).not_null()) .col(ColumnDef::new(Consent::ConsentScope).string_len(100).not_null()) .col( ColumnDef::new(Consent::Status) .string_len(20) .not_null() .default("granted"), ) .col(ColumnDef::new(Consent::GrantedAt).timestamp_with_time_zone()) .col(ColumnDef::new(Consent::RevokedAt).timestamp_with_time_zone()) .col(ColumnDef::new(Consent::ExpiryDate).date()) .col(ColumnDef::new(Consent::ConsentMethod).string_len(30)) .col(ColumnDef::new(Consent::WitnessName).string_len(100)) .col(ColumnDef::new(Consent::Notes).text()) .col( ColumnDef::new(Consent::CreatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col( ColumnDef::new(Consent::UpdatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col(ColumnDef::new(Consent::CreatedBy).uuid()) .col(ColumnDef::new(Consent::UpdatedBy).uuid()) .col(ColumnDef::new(Consent::DeletedAt).timestamp_with_time_zone()) .col( ColumnDef::new(Consent::Version) .integer() .not_null() .default(1), ) .to_owned(), ) .await?; manager .create_index( Index::create() .name("idx_consent_tenant_patient") .table(Consent::Table) .col(Consent::TenantId) .col(Consent::PatientId) .to_owned(), ) .await?; Ok(()) } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(Consent::Table).to_owned()) .await } } #[derive(DeriveIden)] enum Consent { Table, Id, TenantId, PatientId, ConsentType, ConsentScope, Status, GrantedAt, RevokedAt, ExpiryDate, ConsentMethod, WitnessName, Notes, CreatedAt, UpdatedAt, CreatedBy, UpdatedBy, DeletedAt, Version, }