多租户共享数据库,租户之间具有公共数据
我有一个多租户应用程序,带有一个数据库,所有记录都包含 TenantId。然而,在某些情况下,我们希望拥有可供所有租户受益的通用数据。我们实际上正在重建一个旧的 ASP(黑色,而不是经典)应用程序,在该应用程序中,他们有一个 TenantId =1,所有常见的东西都在其中。这对我来说似乎有点老套,因为你最终会得到这样的查询:其中 TenantId=342 ||租户ID=1。
有更好的方法吗?
谢谢,
拉伊夫
I have a multi tenant application with a single database with all records containing a TenantId. There are, however, situations where we want to have common data for all tenants to benefit from. We are actually rebuilding an old ASP( noir, not clasic ) app and in that app they have a TenantId =1 where all the common stuff goes. This seems kind of hacky to me as you end up with queries that say where TenantId=342 || tenantId=1.
Is there a better way to do this?
Thanks,
Raif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恕我直言,您可以通过将您想要作为全局记录或在不同租户之间共享的记录的租户 I 列值设置为 null 来实现此目的。如果您需要存储租户特定值,只需将该值存储在租户 Id 列中租户 Id 值 SRT 的行中即可。通过这种方式,您可以将租户特定值和全局值驻留在单个表中,并且易于检索。
如果可能需要进一步讨论,请发表您的理解。
IMHO, you can achieve this by having the tenant I'd column value as null for thee record that you want to have as global or shared across the different tenants. In case you need to store the tenant specific value, just store the value in a row with the tenant I'd value SRT in the tenant I'd column. In this way, you can have both the tenant specific and global value reside in a single table with ease of retrieval.
Post your understanding if further discussion may be required.
这里提到了一些方法,包括 Johnathan M 关于“私有”字段的建议。我自己一直在研究这个问题,看起来行安全可能是一个解决方案。例如,与 Postgres。
A few approaches are mentioned here, including Johnathan M's suggestion of a "private" field. Have been looking into the issue myself, and it looks like row security may be a solution. For example, with Postgres.