Description
This week I worked on completing the Noticed Integration into CircuitVerse, this was one of the challenging and most productive week ever as I have learned:
- Rails console effective usage.
- ActiveRecords
- Migration.
- Controllers.
- Views rails.
So on the last meeting, I showed the demo of the notification functionality to the mentors and they stated it that there is some more small changes in the UI and to migrate the old data of Activity Notification.
I completed the task for helper methods, UI and some cleanups. But the most challenging task for me was to migrate data from one table to another table with different configuration. Aboobacker shared a migration file that contains SQL query for the migration but that was comparatively simpler then what I need to do in this task!
So I comeup with many solution to render oldnotification:
-
I thought we can just add a
before_actionfilter with methodload_old_notificationsforuser.So I create a new column inold_notificationtable calledmigratedwith defaultfalse, so whenever the user signin, theload_old_notificationswill run and will check in theold_notificationif themigratedfield isfalse, it will create a new data fornotificationtable and markmigratedastrueinold_notificationtable. -
But I find this as very complex as we are thinking of removing
ActivityNotificationgem and while migrating there is model method needed to get the path of the notification, so I drop this solution and jump into next and next, I failed and finally come up with the solution to useActiveRecordsinmigration(it worked but not preferable) so here is my migration file look like:
class PopulateNotificationData < ActiveRecord::Migration[7.0]
include ActivityNotification
def change
Notification.find_each do |data|
newnotification = NoticedNotification.first_or_initialize(
:recipient_type => data.target_type,
:recipient_id => data.target_id,
:type => "PreviousNotification",
:params => {
user_id: data.notifier_id,
path: data.notifiable_path,
message: data.notifiable.printable_notifiable_name(data.target),
type: data.notifiable_type
},
:read_at => data.opened_at
)
newnotification.save!
end
end
end
I need to change it in SQL query.
So that took me around 4 days but it was worth it, I learned a lot from failures.
This 2 weeks I also :
- Passed Mid-term Evaluation
- Post my first blog on CircuitVerse/Blog regarding first phase of GSoC.
- Attended my first offline hackathon and meet awesome peoples.
Next week plan:
- Complete spec testcases
- Complete migration
- Start working on
push notificationin mobile app.