Advice re: schema design for user-specific role-based properties
I'm building a staff dashboard app for work. Users of this app will each have one or more assigned roles. I've got both a
users table and a roles table, with the relationship between them already established. No issues there.For some (but not all) roles, there will be custom settings that are exclusive to the role. For example, with the Salesperson role there's a default commission percentage for all salespeople, but an individual salesperson might have a commission that overrides that default. While I could create something like a
commission field directly on the users table to store this value, I really don't like to have fields that are only needed in limited use cases. The commission override is just one example of a role-specific setting, and there could be a lot more over time, so I'm trying to think of a more efficient way to save such settings without creating tons of limited-use fields.The idea that I'm leaning toward is to have a multi-purpose
roleSettings field that would store an object kinda like this:The keys in the main object would be document IDs from the
roles table, with the value being an appropriate object containing the available settings for that role.While this feels like the most appropriate way to minimize fields and maximize flexibility, I'm struggling to figure out how to represent that in a schema definition, with an arbitrary number of ID keys, and the value associated with each key being an object with a format specific to that key. Is that even possible with the validator options?
