feature(database/gdb): Implement Row-Level Multi-Tenancy Support #4524
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
gdb目前支持分库分表级别的多租户,补充一个行级多租户的实现主要特性:
租户上下文管理:
WithTenantIdField和WithTenantIdValue函数用于设置租户字段名和值到上下文中DefaultGetTenantIdFieldValue从上下文中获取租户信息模型级租户支持:
Tenant()方法启用多租户功能UnTenant()方法禁用多租户功能TenantOption可配置选项包括:Enable: 控制是否启用租户功能PropagateToJoins: 控制是否将租户条件应用于连接表GetTenantIdFieldValueFunc: 自定义获取租户ID字段和值的函数智能租户条件生成:
无缝集成:
注意事项:
WithTenantIdField设置的tenantIdField在构建过程中会检查对应的表字段中有没有这个字段,所以最好是多表的租户字段都相同,如果有需要我也可以加个配置让大家在不同表映射成不同的字段,看大家有没有需求使用示例:
sql