I am making a database structure for users, who can become part of a group, and within that group the admin of the group can assign as many permissions to a user as they would like.
This part seems easy. I have 4 tables:
USERS GROUPS PERMISSIONS PERMISSIONS_GROUPS
------- --------------------- -------------- -------------------
| UID | | GID | UID(creator) | | PID | NAME | | UID | GID | PID |
I think this is the best way to handle this. I have a few questions about how to handle permissions for the creator of the group, and how to handle permissions if I were to delete a permission or add a permission.
For instance, when a user makes a group. Do I query all of the permissions and in a while
loop insert a PERMISSIONS_GROUPS
record for every row in the permissions
table? If I add a new permission, do I have to query every UID
from the GROUPS
table and run a while
loop to insert the new permission into PERMISSIONS_GROUPS
? I just want to make sure I am not missing something simple here. For structure/scripting I am using MySQL
and PHP
.
Best Answer
A sketch for an alternative approach would be:
This may suit your needs, but it is hard to tell without knowing the exact business rules. Identifiers are of course just bogus and need to be adjusted.