Gonchar1989's avatar

MySQL DB for eCommerce project

Hi there! We have some questions about database for ecommerce project. Please give us your advices. Thank you.

  1. We have 3 roles: buyer, seller and super admin. Q: Should we create 3 tables in mysql for each role or we should put all users in one table and add role_id column from another table roles?

  2. We have got this question many times during the dev process. So we would like to ask somebody more expirienced. We have table orders (id, buyer_id, seller_id) and table comments (id, order_id, buyer_id, seller_id, comment). We also put buyer_id and seller_id in comments table, but actualy we can get this information by checking order_id in orders table. Q: what is the best way to read data from different tables, wich contain same data? Maybe we should put comment field to orders table?

0 likes
1 reply
Tray2's avatar
  1. All user shoulds be in the users table.

  2. Depends on what you are aming for. Orders table definetly need both user_id and seller_id and a order number since a user and seller can have multiple orders. Then you probaly needs an order_lines table since an order can contain more then one item. As for comments if only one role i.e. seller updates this field then add it to the orders table if both can write comments make it a table of it's own.

The best way to read data? Depends on what you are fluent in. Either you use eloquent and the relationships there or you use plain SQL.

My personal opinion is to use Eloquent for the simple stuff like listing all the orders for a user, working with one or two tables when there is more tables involved I'd go to the SQL.

Please or to participate in this conversation.