feat(health): 新增 blind_indexes 表 + Entity 支持 PII 盲索引搜索
This commit is contained in:
21
crates/erp-health/src/entity/blind_index.rs
Normal file
21
crates/erp-health/src/entity/blind_index.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "blind_indexes")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub entity_type: String,
|
||||
pub entity_id: Uuid,
|
||||
pub field_name: String,
|
||||
pub blind_hash: String,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -6,6 +6,7 @@ pub mod article_article_tag;
|
||||
pub mod article_category;
|
||||
pub mod article_revision;
|
||||
pub mod article_tag;
|
||||
pub mod blind_index;
|
||||
pub mod critical_value_threshold;
|
||||
pub mod consent;
|
||||
pub mod consultation_message;
|
||||
|
||||
@@ -88,6 +88,7 @@ mod m20260427_000085_processed_events;
|
||||
mod m20260427_000086_enable_rls_all_tables;
|
||||
mod m20260427_000087_audit_logs_hash_chain;
|
||||
mod m20260428_000088_rls_policy_strict;
|
||||
mod m20260428_000089_blind_indexes;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -183,6 +184,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260427_000086_enable_rls_all_tables::Migration),
|
||||
Box::new(m20260427_000087_audit_logs_hash_chain::Migration),
|
||||
Box::new(m20260428_000088_rls_policy_strict::Migration),
|
||||
Box::new(m20260428_000089_blind_indexes::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user