title: Which method of storing USERS, ROLES & TEAMS in my relational DB is most efficient
body: <p>I'm working on developing an app as part of my college assignment. It's a project management app, and I'm having trouble deciding the best way to store users and teams in my Postgres DB. Basically, users can signup and create/join teams. A user can be a part of multiple teams (each working on multiple projects). Users also have roles in teams (with varying permissions according to the role) and while they have only one role in a given team, they may have a different role in another one. In addition, users can mark some of their teams as favorites for easy access through the front-end.</p>
  
  <p>I've come up with 3 ERDs to solve this. </p>
  
  <p>First, store all users in one table and and all teams in another. Users table has all the data pertaining to a user, while the team table has the team data along with the members,roles and whether or not a user has marked this team as a favorite - like below.</p>
  
  <p><img src="https://i.stack.imgur.com/0zTSi.png" alt="ERD1"></p>
  
  <p>This will have a lot of data duplication - if a team has a hundred members, there will be 100 entries where teamid, name, description are the same.</p>
  
  <p>So, in v2 I separated them and added a members table. Now, each team is saved once, and so is each user. A reference to the team and user is made each time a user joins/creates a team and is stored in the members table along with the user's role and whether or not they have favorited the team. </p>
  
  <p><img src="https://i.stack.imgur.com/gByyu.png" alt="ERD2"> </p>
  
  <p>But, I thought it might be bad to save roles as a string. If roles ever need to be changed/updated or I need to add new roles/rename roles, it would be easier with an ID rather than a string (I think). </p>
  
  <p>So, then I came up with this. </p>
  
  <p><img src="https://i.stack.imgur.com/a57tL.png" alt="ERD3"> </p>
  
  <p>Now all roles, users and teams are stored once (its possible that I've made the roles table into something like a lookup table, which I've heard is a bad practice). All these can be referenced in the members table.</p>
  
  <p>My DBMS concepts are a little weak though I have tried my best to follow steps to normalize it and bring it into BCNF form. But I'm still unsure if I've done this right, or what to fix if something is wrong.</p>
  
  <p>So essentially, I would like to know:</p>
  
  <ol>
  <li>Is my table structure correct or incorrect?</li>
  <li>Should everything be split into multiple tables, or is some data duplication okay (since I can use multiple or creative queries to get whatever I need)?</li>
  </ol>