1 # This migration changes the relationships for the events created for comments
2 # Instead of being related to the actual comment, the target is set to be the repository
3 # Further on, the id of the comment (we can assume there is one, since this is a comment type event),
4 # is stored in the data field instead of the target
5 class HookingCommitEventsToRepository < ActiveRecord::Migration
7 events = Event.find_all_by_action(Action::COMMENT)
9 comment_id = event.target.id
10 repository = Repository.find(event.target.target_id) # The event's target has a target_id being the ID of the repository
11 event.update_attributes(:target_type => 'Repository', :target_id => repository.id, :data => comment_id)
16 events = Event.find_all_by_action(Action::COMMENT)
17 events.each do |event|
18 comment = Comment.find(event.data)
19 event.update_attributes(:target_type => 'Comment', :target_id => comment.id, :data => nil)