Files
hms/crates/erp-server/migration/src/m20260428_000089_blind_indexes.rs
iven 298e439fb2
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled
feat(health): 新增 blind_indexes 表 + Entity 支持 PII 盲索引搜索
2026-04-28 11:31:54 +08:00

94 lines
3.1 KiB
Rust

use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[derive(Iden)]
enum BlindIndex {
Table,
Id,
TenantId,
EntityType,
EntityId,
FieldName,
BlindHash,
CreatedAt,
UpdatedAt,
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(BlindIndex::Table)
.col(
ColumnDef::new(BlindIndex::Id)
.uuid()
.not_null()
.primary_key()
.default(PgFunc::gen_random_uuid()),
)
.col(ColumnDef::new(BlindIndex::TenantId).uuid().not_null())
.col(
ColumnDef::new(BlindIndex::EntityType)
.string_len(64)
.not_null(),
)
.col(ColumnDef::new(BlindIndex::EntityId).uuid().not_null())
.col(
ColumnDef::new(BlindIndex::FieldName)
.string_len(64)
.not_null(),
)
.col(
ColumnDef::new(BlindIndex::BlindHash)
.string_len(64)
.not_null(),
)
.col(
ColumnDef::new(BlindIndex::CreatedAt)
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(BlindIndex::UpdatedAt)
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.index(
Index::create()
.col(BlindIndex::TenantId)
.col(BlindIndex::EntityType)
.col(BlindIndex::FieldName)
.col(BlindIndex::BlindHash)
.unique(),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_blind_hashes")
.table(BlindIndex::Table)
.col(BlindIndex::TenantId)
.col(BlindIndex::EntityType)
.col(BlindIndex::FieldName)
.col(BlindIndex::BlindHash)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(BlindIndex::Table).to_owned())
.await
}
}