Handle not ready repos
[gitorious.git] / db / migrate / 20090330091652_hooking_commit_events_to_repository.rb
blob305f20a59ac268f384e64b6dbe6c1adf739af296
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
6   def self.up
7     events = Event.find_all_by_action(Action::COMMENT)
8     events.each do |event|
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)
12     end
13   end
15   def self.down
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)
20     end
21   end
22 end