SaaS、多租户(共享模式)- 一张表还是两张表?

发布于 2024-11-18 22:00:26 字数 717 浏览 4 评论 0原文

我正在为 SaaS 应用程序创建多租户(共享架构)数据库。该应用程序将允许订阅公司(租户)与其他公司(帐户 - 例如供应商、业务合作伙伴、客户等)进行协作。用户将与租户和帐户相关联。

这是我的问题:从设计角度来看,将租户和帐户放在一张表中可以吗?我想“是”,因为公司就是公司,无论他们是租户还是帐户。此外,我正在考虑使用 is_tenant(布尔值)等字段来破译租户,并可能将租户特定信息放在单独的表中。这里是一个建议的模式:

  • 公司(company_id,is_tenant,名称,地址等)
  • 用户(user_id,名称,电子邮件,用户名,密码等)
  • company_users(company_id,user_id)
  • tenant_information(company_id,billing_address,billing_state等) )
  • tenant_accounts (tenant_id, account_id) – 将租户与帐户相关联[其中tenant_id和account_id将是公司表]

我通读了 MS 文章,多租户数据架构虽然有帮助,但它没有提供答案。

关于此模式的任何其他想法/评论/陷阱将不胜感激。

提前致谢。

I am creating a multi-tenant (shared-schema) database for a SaaS application. The application will allow the subscribing company (the tenant) to collaborate with other companies (accounts – such as vendors, business partners, customers, etc.). Users will be associated with both the tenant and the accounts.

Here is my question: from a design perspective, is it okay to put the tenants and accounts in one table? I’m thinking “yes” because a company is a company regardless of whether they are a tenant or an account. Further, I was thinking of deciphering a tenant with a field such as is_tenant (Boolean) and perhaps put tenant specific information in a separate table. Here is a proposed schema:

  • companies (company_id, is_tenant, name, address, etc.)
  • users (user_id, name, email, username, password, etc.)
  • company_users (company_id, user_id)
  • tenant_information (company_id, billing_address, billing_state, etc.)
  • tenant_accounts (tenant_id, account_id) – associates tenants with accounts [where tenant_id and account_id would be f_keys to the companies table]

I read through the MS article, Multi-Tenant Data Architecture and, while helpful, it was short on providing an answer.

Any additional thoughts/comments/pitfalls regarding this schema would be greatly appreciated.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白鸥掠海 2024-11-25 22:00:26

我也同意这一点...如果所有属性都相同,则无需为此创建另一个表(数据协定)

我们也在使用类似的东西。在 SAAS 框架中,您在创建表时始终需要小心,否则将需要花费巨大的精力来重构和创建表。迁移。

不过我有一个问题!无法看到任何包含公司特定信息(不是您的租户)的“Company_Information”表

I would also agree with that... if all the properties are same, then there is no need to create another table (data contract) for that.

We are also using something of that sort. In a SAAS framework you always need to be careful in creating tables otherwise it will take a huge effort to refactor & migrate.

I have a question though! Cant see any "Company_Information" table which will have company specific info (which are not your tenants)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文