Skip to content

[How To] Backfill Activity for a model

Brian Kelly edited this page Jul 29, 2017 · 2 revisions

If you are adding public_activity to an existing app you may have old models that you'd like to fill-in the activity for.

Here's a simple migration that will fill in the create activity for all comments that existed on your site.

class BackfillActivity < ActiveRecord::Migration
  def up
    Comment.find_each do |comment|
      comment.create_activity :create, created_at: comment.created_at, updated_at: comment.created_at 
    end
  end

  def down
    PublicActivity::Activity.delete_all
  end
end