DEV Community

Discussion on: How best do I structure my User database?

Collapse
 
fedeagripa profile image
fedeagripa

Just curious when you talk about admins, are they AdminUsers like ActiveAdmin ones? if so you have a first cristal clear separation there (but ActiveAdmin solves it for you, so no worries). If not..
You can take 2 vias:

  • Create 3 different tables
    You will probably repeat a lot of code and add devise to all of them, so it does not look like a good idea (besides only thinking in the database seems so a good call)

  • STI solution
    This is basically adding a type field to your user, and I think it would be the best solution for you. You can then add (Pundit)[github.com/varvet/pundit] for authorization to handle your specific user roles permissions (access dashboard, analytics, manage building, etc).

So conclusion:
I would recommend going for an STI and add Pudit to handle authorization (you can also use rolify or cancancan if you want, as they were commented in the thread).
Hope this helps you but feel free to dm me if you want any help or maybe a brief pair session :)