I’m still a jr programmer, so I’m just trying to get an idea for best practices. If I have four notification streams [Messages, Events, Comments, Location based] should I create a separate table for each event type or should I create one table and add a column describing the event type.
(Assuming moderate traffic, rails, AR, Postgre and each table having fairly similar columns [id, user_id, other_object_id, message, time, …])
Thanks for the advice!
That’s probably a Software Design question. Do you have common behavior between all types of Notifications? If the answer is no, then just create a different model for each kind of Notification.
However, most of the times, you have a good amount of shared behavior for the Notifications, even the same behaviors. If the notifications all looks the same, and there is just some tiny differences between each other, just add a notification_type column and define the small behavior based on the value of that column. This will be the quicker and pragmatic way.
Now if you want to implement a good design pattern, you want to implement ActiveRecord inheritance, where you will define the common behavior on a Notification model, and then Messages, Events, Comments, etc. will inherit from this model.
You can look for more information about Active Record inheritance on the Rails Documentation: http://api.rubyonrails.org/classes/ActiveRecord/Base.html, the Martin Fowler pattern http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html and you will find different examples across the web