feat(gateway): 多租户增量2 —— gorm 租户插件按上下文自动隔离查询(SaaS P1)
统一强制、别靠人肉:受租户模型标记 isTenantScoped() 后,store/tenant_scope.go 的 gorm 回调按请求 ctx 自动给查询加 WHERE tenant_id、创建自动填 tenant_id。 - KB / Agent 加 TenantID 字段 + isTenantScoped() 标记 - middleware.TenantContext 把 tenant 注入 request context 供 store 插件读取 - ctx 无租户(系统/回填/未登录)不过滤,保留跨租户操作能力 - 启动 BackfillRowTenants 回填存量行 tenant_id=owner 默认租户(幂等) live 验证:创建自动写 tenant_id ✓;同 owner 不同 tenant 的行被查询过滤 ✓。 Doc/DocLink(异步入库)、Task/Eval(无 owner)留待增量2b。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,7 @@ func OpenPostgres(dsn string) *Postgres {
|
||||
log.Printf("[store] postgres AutoMigrate 失败,降级运行: %v", err)
|
||||
return &Postgres{}
|
||||
}
|
||||
registerTenantScope(db) // 多租户:受租户模型的查询/创建自动按上下文注入 tenant_id(统一强制隔离)
|
||||
log.Println("[store] postgres connected & migrated (雪花 id + 软删 规约)")
|
||||
return &Postgres{db: db}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user