Description
This week I worked on completing the Noticed Integration into CircuitVerse, this was one of the challenging and most productive weeks ever as I have learned:
- Rails console effective usage.
- ActiveRecords
- Migration.
- Controllers.
- Views rails.
So in the last meeting, I showed the demo of the notification functionality to the mentors and they stated that there are some minor 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 configurations. Aboobacker shared a migration file that contains SQL
the query for the migration but that was comparatively simpler than what I needed to do in this task!
So I have comeup with many solutions to render old notifications:
I thought we can just add a
before_action
filter with methodload_old_notifications
foruser
.So I create a new column inold_notification
table calledmigrated
with defaultfalse
, so whenever the user signin, theload_old_notifications
will run and will check in theold_notification
if themigrated
field isfalse
, it will create a new data fornotification
table and markmigrated
astrue
inold_notification
table.But I find this as very complex as we are thinking of removing
ActivityNotification
gem 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 useActiveRecords
inmigration
(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 notification
in mobile app.
Top comments (0)