feat: 添加租户隔离保护触发器的管理方法,并更新迁移文档

This commit is contained in:
2026-07-28 14:45:33 +08:00
parent 99e4e43122
commit 5e993298e7
5 changed files with 61 additions and 4 deletions

View File

@@ -179,8 +179,10 @@ EF Core 负责实体、Fluent Configuration、Migration 生成和迁移执行入
实现要求:
- 触发器 SQL 必须集中在基础设施层,例如 `Tiku.Infrastructure/Persistence/PostgreSqlTenantConstraintSql.cs`
- Migration 只调用集中 SQL helper,例如 `migrationBuilder.Sql(PostgreSqlTenantConstraintSql.CreateTenantQuestionReferenceGuard)`
- Migration 只调用集中 helper`migrationBuilder.EnsureTenantIsolationGuards()` / `migrationBuilder.DropTenantIsolationGuards()`
- 重建或压缩 `InitialSchema` 后,必须在 `Up()` 末尾调用 `EnsureTenantIsolationGuards()`,在 `Down()` 开头调用 `DropTenantIsolationGuards()`
- 不允许把触发器 SQL 零散复制到多个 migration。
- Migration script 测试必须断言 guard function 和 trigger 存在,避免重建基线时漏掉数据库硬防线。
- 每个触发器必须有真实 PostgreSQL 集成测试覆盖允许路径和拒绝路径。
- 如果将来新增类似“平台或本租户”的 owner 规则,优先补集中 SQL helper 和模型/集成测试,不要只靠 Service 手写校验。