What is the best way to store permissions in a database that involve more than 2 levels? Currently there's only 2 levels of permissions and they are stored in a bridge entity table like this:
UID | Buildings | Floor
------------------------
1 | A, B, C | F9
There's also another table called Exceptions that has the same structure which indicates that users should NOT have permissions for those:
UID | Buildings | Floor
------------------------
1 | null | C4
So in my example above, user 1 would have permissions to floor 9 in building F, all the rooms in buildings A, B and C, but not floor 4 in C.
The new requirement is to add an even more granular level of permissions, rooms on floors. So the code would look something like A1A, A1B, etc. The buildings and rooms are always alphabetic and the floor number is always numeric. I cannot change the format of these codes as they are coming from an external source.
What is the best way to handle a situation like this? I know Linux handles file permissions with group and user with a bit string, but with thousands of rooms in my case that doesn't sound feasible, and also the user/group thing is only two levels.
I've considered just adding a new column called Rooms
and continuing with the comma-separated string but is there a better way? If it matters, I'm using MySQL.