简体   繁体   English

多租户应用程序的数据库设计

[英]Database design for Multi tenant application

for a multi tenant app, we have the following database design: 对于多租户应用程序,我们具有以下数据库设计: 在此处输入图片说明

which is based on shared database approach. 这是基于共享数据库的方法。 Since we are identifying the tenants using company id (each company has a different set of employees and their tasks and so on), my question is 由于我们使用公司ID来识别租户(每个公司的员工和他们的任务等等都有不同的集合),我的问题是

Do we need a companyId key in the Task table also so that every record of task can be clearly identified using the companyId OR we should always use a Join? 我们是否还需要在Task表中使用companyId键,以便可以使用companyId清楚地标识每条任务记录,或者我们应该始终使用Join?

because if we use the companyId in Task that would not be a properly normalized database as the Task is would relate to a company and an employee which is also related to the company. 因为如果我们在Task中使用companyId,因为该Task与公司无关,而该TaskId却不是一个适当规范化的数据库,则它会与公司相关,而员工也与该公司相关。

It is a matter of opinion. 这是见仁见智。 My take is to make companyId as a part of primary key and hence a mandatory field in every table. 我的想法是使companyId作为主键的一部分,因此成为每个表中的必填字段。

In a multi tenant application, we should ensure that data does not get added in the table without a company code. 在多租户应用程序中,我们应该确保没有公司代码就不会在表中添加数据。 Without making it a part of primary key or a non null field, it is upto program logic to ensure that. 在不使其成为主键或非空字段的一部分的情况下,由程序逻辑来确保这一点。 In my opinion, DB should also ensure that. 我认为,DB也应确保这一点。 Second issue is with the table task id. 第二个问题是表格任务ID。 It is possible for 2 companies to have same employee id's and same task ids. 两个公司可能具有相同的员工ID和相同的任务ID。 DB should not restrict that. DB不应对此进行限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM