From 298e439fb246092b100fb48133cfb5e02ff7df88 Mon Sep 17 00:00:00 2001 From: iven Date: Tue, 28 Apr 2026 11:31:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(health):=20=E6=96=B0=E5=A2=9E=20blind=5Fin?= =?UTF-8?q?dexes=20=E8=A1=A8=20+=20Entity=20=E6=94=AF=E6=8C=81=20PII=20?= =?UTF-8?q?=E7=9B=B2=E7=B4=A2=E5=BC=95=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/erp-health/src/entity/blind_index.rs | 21 +++++ crates/erp-health/src/entity/mod.rs | 1 + crates/erp-server/migration/src/lib.rs | 2 + .../src/m20260428_000089_blind_indexes.rs | 93 +++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 crates/erp-health/src/entity/blind_index.rs create mode 100644 crates/erp-server/migration/src/m20260428_000089_blind_indexes.rs diff --git a/crates/erp-health/src/entity/blind_index.rs b/crates/erp-health/src/entity/blind_index.rs new file mode 100644 index 0000000..e899766 --- /dev/null +++ b/crates/erp-health/src/entity/blind_index.rs @@ -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 {} diff --git a/crates/erp-health/src/entity/mod.rs b/crates/erp-health/src/entity/mod.rs index a2466a9..1b9f154 100644 --- a/crates/erp-health/src/entity/mod.rs +++ b/crates/erp-health/src/entity/mod.rs @@ -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; diff --git a/crates/erp-server/migration/src/lib.rs b/crates/erp-server/migration/src/lib.rs index 729c135..9b30f54 100644 --- a/crates/erp-server/migration/src/lib.rs +++ b/crates/erp-server/migration/src/lib.rs @@ -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), ] } } diff --git a/crates/erp-server/migration/src/m20260428_000089_blind_indexes.rs b/crates/erp-server/migration/src/m20260428_000089_blind_indexes.rs new file mode 100644 index 0000000..c3943eb --- /dev/null +++ b/crates/erp-server/migration/src/m20260428_000089_blind_indexes.rs @@ -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 + } +}