简体   繁体   English

MySQL表关系布局(多对多含糊)

[英]MySQL table relationship layout (many-to-many with ambiguity)

I have tables for accounts, groups and projects. 我有用于帐户,组和项目的表。 Now I want to describe the access privileges of accounts and groups regarding accounts and projects. 现在,我要描述有关帐户和项目的帐户和组的访问权限。 For projects there is read, write and no access while for accounts there is only access and no access. 对于项目,只能进行读取,写入和访问,而对于帐户,则只能进行访问和访问。

The first solution that came to my mind was to create an access table with this layout: 我想到的第一个解决方案是使用以下布局创建访问表:

INT accessed_account_or_project_id
INT accessor_account_or_group_id
BOOLEAN accessed_is_project
BOOLEAN accessor_is_group
BOOLEAN canWrite

Is this a good structure or should I create 2 separate tables for project and account access privileges or possibly even 4 for the different accessors? 这是一个好的结构,还是我应该为项目和帐户访问权限创建2个单独的表,或者为不同的访问者甚至创建4个?

I found some general advice about many-to-many relationships but in this case I am uncertain as a newbie because of the ambiguity and canWrite . 我发现了有关多对多关系的一些一般性建议,但是在这种情况下,由于模棱两可和canWrite的缘故,我不确定作为新手。

You shouldn't have a column that represents two different sets of data _or_ , so I would suggest you go with a four table solution for the possible combinations of account/project/group permissions mappings. 您不应有代表两套不同数据_or_ ,因此我建议您使用四表解决方案来解决帐户/项目/组权限映射的可能组合。 This should make it easy to enforce constraints to prevent conflicts in permissions. 这应该使强制约束变得容易,以防止权限冲突。

The existence of an entry in the table can indicate access, but projects has the additional access level. 表中存在一个条目可以指示访问权限,但是projects具有其他访问权限级别。 As long as you don't think that there will be more access levels introduced later, I think that the canWrite column on the two projects tables is fine. 只要您不认为以后会介绍更多访问级别,我认为两个项目表上的canWrite列就可以了。 Otherwise you could have a link to another table with a set of permissions types. 否则,您可以链接到具有一组权限类型的另一个表。

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

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