简体   繁体   中英

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?

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 .

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. 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. 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. Otherwise you could have a link to another table with a set of permissions types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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