I am trying to implement a historyactivity tracking system in Ruby on Rails for an API only application.
Every time an update is done (title, ownership or state changes) I want to log it in an historyactivity table which will be display along side the letter on the application.
It wouldshould look like GitHub issues, where we can see who did what. Being able to reference users, link to their profile, says that someone change the title from "something" to "another thing", etc.
I started to create a historyactivity table as follow :
id(primary key)letter_id(foreign_key onletter)created_at(datetime)user_id(foreign_key onuser)type(enum { STATUS , TRANSFER , METADATA })history_idactivity_id(integer pointing on table id)
And created one table for each enum entry in type column and load them manually using the history_idactivity_id. But I found it pretty ugly because:
historyactivity = HistoryActivity.find(1)
if (historyactivity.type == "STATUS")
StatusHistoryStatusActivity.find(historyactivity.history_idactivity_id)
elsif (historyactivity.type == "TRANSFER")
TransferHistoryTransferActivity.find(historyactivity.history_idactivity_id)
...
Based on the historyactivity layout of the first idea, instead of having on column with the I thought about having additional nullable columns holding a foreign_key toward each enum entries tables :
id(primary key)letter_id(foreign_key onletter)created_at(datetime)user_id(foreign_key onuser)type(enum { STATUS , TRANSFER , METADATA })status_history_idstatus_activity_idtransfer_history_idtransfer_activity_idmetadata_history_idmetadata_activity_id
Doesn't look great; if I want to add a new kind of historyactivity event, I will have to create an extra column for each row...
historyactivity = HistoryActivity.find(1)
if (historyactivity.type == "STATUS")
historyactivity.status_historystatus_activity
elsif (historyactivity.type == "TRANSFER")
historyactivity.transfer_historytransfer_activity
...
Create 3 different tables: status_historystatus_activity, transfer_historytransfer_activity and metadata_historymetadata_activity. Query them separately, sort them by creation date before returningserializing into JSON.