Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Change 'history' by 'activities'
Source Link

Design event trackingactivities / historyevents logging (ex: fields update) in RDBMS

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 on letter)
  • created_at (datetime)
  • user_id (foreign_key on user)
  • 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 on letter)
  • created_at (datetime)
  • user_id (foreign_key on user)
  • type (enum { STATUS , TRANSFER , METADATA })
  • status_history_idstatus_activity_id
  • transfer_history_idtransfer_activity_id
  • metadata_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.

Design event tracking / history in RDBMS

I am trying to implement a history 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 history table which will be display along side the letter on the application.

It would look like GitHub issues, where we can see who did what. Being able to reference users, link to their profile, etc.

I started to create a history table as follow :

  • id (primary key)
  • letter_id (foreign_key on letter)
  • created_at (datetime)
  • user_id (foreign_key on user)
  • type (enum { STATUS , TRANSFER , METADATA })
  • history_id (integer pointing on table id)

And created one table for each enum entry in type column and load them manually using the history_id. But I found it pretty ugly because:

history = History.find(1)
if (history.type == "STATUS")
  StatusHistory.find(history.history_id)
elsif (history.type == "TRANSFER")
  TransferHistory.find(history.history_id)
...

Based on the history 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 on letter)
  • created_at (datetime)
  • user_id (foreign_key on user)
  • type (enum { STATUS , TRANSFER , METADATA })
  • status_history_id
  • transfer_history_id
  • metadata_history_id

Doesn't look great; if I want to add a new kind of history event, I will have to create an extra column for each row...

history = History.find(1)
if (history.type == "STATUS")
  history.status_history
elsif (history.type == "TRANSFER")
  history.transfer_history
...

Create 3 different tables: status_history, transfer_history and metadata_history. Query them separately, sort them by creation date before returning JSON.

Design activities / events logging (ex: fields update) in RDBMS

I am trying to implement a activity 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 activity table which will be display along side the letter on the application.

It should 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 activity table as follow :

  • id (primary key)
  • letter_id (foreign_key on letter)
  • created_at (datetime)
  • user_id (foreign_key on user)
  • type (enum { STATUS , TRANSFER , METADATA })
  • activity_id (integer pointing on table id)

And created one table for each enum entry in type column and load them manually using the activity_id. But I found it pretty ugly because:

activity = Activity.find(1)
if (activity.type == "STATUS")
  StatusActivity.find(activity.activity_id)
elsif (activity.type == "TRANSFER")
  TransferActivity.find(activity.activity_id)
...

Based on the activity 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 on letter)
  • created_at (datetime)
  • user_id (foreign_key on user)
  • type (enum { STATUS , TRANSFER , METADATA })
  • status_activity_id
  • transfer_activity_id
  • metadata_activity_id

Doesn't look great; if I want to add a new kind of activity event, I will have to create an extra column for each row...

activity = Activity.find(1)
if (activity.type == "STATUS")
  activity.status_activity
elsif (activity.type == "TRANSFER")
  activity.transfer_activity
...

Create 3 different tables: status_activity, transfer_activity and metadata_activity. Query them separately, sort them by creation date before serializing into JSON.

Remove Google Drive reference. It could lead to the wrong concept of history I want. Enhance GitHub ref.
Source Link

It would look like GitHub issues or Google Drive historyGitHub issues, where we can see who did what. Being able to reference users, link to their profile, etc.

It would look like GitHub issues or Google Drive history, where we can see who did what.

It would look like GitHub issues, where we can see who did what. Being able to reference users, link to their profile, etc.

edited tags
Link
Source Link
Loading