How would you design a database to manage multi organisation?
(ie 1 user can own/manage more than 1 organisation)
Example
- Xero (www.xero.com), you can login to xero then select the company on the list that you want to manage. I think freshbook has something simular.
USER_ACCESS
- Id
- CompanyUserId (UserId of company)
- UserId (UserId that will manages company)
USER_PERMISSION
- Id
- UserAccessId
- CanViewM
- CanEditM
…. - CanViewN
- CanEditN
You should not mix users and logins. They should be kept treated as seperate tables/objects. As ones role in one company might not be the same role as in the other company.
Also do not create a permission table with one column for each possible permission. Instead you should create one row per allowed permission. (and if needed one table defining all permissions)
Hence you should have tables like:
USER_ACCOUNT (used to define logins)
USER
PERMISSIONS
USER_ALLOWED_PERMISSIONS
When logging in, simply check the USER table if more than one row is returned for the account and display a select user form if needed.