An user is connected to an organization by some role. Lets say there are 2 roles freelancer and employee.
One employee can only be a part of one organization and if he is an employee then he can't be a freelancer. Whereas a freelancer can be connected to multiple organization and he also can't be an employee.
In short, Freelancer and Employee both are users. Freelancer is connected to Organization via many to many relationship. Employee is connected to Organization via one to many relationship.
What I have thought:
user{
id,
name,
other_fields,
}
organization{
id,
other_fields
}
freelancer{
user_id,
organization_id,
Primary_Key(user_id, organization_id)
}
employee{
user_id,
organization_id,
Primary_key(user_id),
}
There is one catch here, though. The constraint of being either a freelancer or an employee but not both has to be implemented at the application level.
- What are the pros and cons of above schema?
- What are other possible alternatives to design schema?
- What if there are more category of users? Current schema requires addition of new table if a new role of user s created. Is it ok or bad?
- Database maintenance is also a concern that making a schema which should not make maintenance a problem