DEV Community

Cover image for GSoC 2022 CircuitVerse | Week 7 and 8 Report
vedant-jain03
vedant-jain03

Posted on • Updated on

GSoC 2022 CircuitVerse | Week 7 and 8 Report

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:

  1. I thought we can just add a before_action filter with method load_old_notifications for user.So I create a new column in old_notification table called migrated with default false, so whenever the user signin, the load_old_notifications will run and will check in the old_notification if the migrated field is false, it will create a new data for notification table and mark migrated as true in old_notification table.

  2. 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 use ActiveRecords in migration (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
Enter fullscreen mode Exit fullscreen mode

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)