I have a hierarchical data model I am creating in a SQL / relational database.
The relevant entities are:
- Institutions have one or more
- Buildings, which have one or more
- Rooms
(Each Room has exactly one parent Building, and each Building has exactly one parent Institution).
There are also Users who can have some roles at any level on the hierarchy. The possible Roles are:
- Owner
- Property manager
- Occupant
Having a role at one level of the hierarchy implicitly grant that role at all lower levels (e.g. if someone is an Owner of an Institution, they are considered to be an Owner of all Buildings and Rooms in that institution).
Some examples:
- Alice is an:
- Owner of Institution A1 (and therefore implicitly an owner of all buildlings and rooms belonging to that institution)
- Occupant of Building B1, B2, and B7 in Institution B
- Bob is an Occupant of Room R1 in Institution X's Building Y
- Cindy is an:
- Property manager of Building-B1 of institution B
- Property manager of Building C3 of Institution C
- Owner of Institution D
- Occupant of Room R7, R8, and R11 in Institution M's Building N
What is a good way of modeling these user roles across these entities in a relational database?