Handle not ready repos
[gitorious.git] / db / migrate / 20090730103419_migrate_custom_merge_request_statuses.rb
blob54f9a5d1d19064d3f00bd614e2d2d1230162c3ae
1 module Gitorious
2   class Project < ActiveRecord::Base
3     default_scope :conditions => {}
4   end
5 end
7 class MigrateCustomMergeRequestStatuses < ActiveRecord::Migration
8   def self.up
9     transaction do
10       Gitorious::Project.all.each do |project|
11         if !project.merge_request_custom_states.blank?
12           project.merge_request_custom_states.each do |open_state|
13             project.merge_request_statuses.create!({
14                 :name => open_state,
15                 :state => MergeRequest::STATUS_OPEN,
16                 :color => "#408000" # green-ish
17               })
18           end
19         else
20           project.merge_request_statuses.create!({
21               :name => "Open",
22               :state => MergeRequest::STATUS_OPEN,
23               :color => "#408000"
24           })
25         end
27         ["Merged", "Rejected"].each do |closed_state|
28           project.merge_request_statuses.create!({
29               :name => closed_state,
30               :state => MergeRequest::STATUS_CLOSED,
31               :color => "#AA0000" # red-ish
32           })
33         end
34       end
35     end
36   end
38   def self.down
39     transaction do
40       Gitorious::Project.all.each do |project|
41         project.merge_request_statuses.each do |state|
42           next unless state.open?
43           project.merge_request_custom_states << state.name
44           project.merge_request_custom_states.uniq!
45           project.save!
46         end
47       end
48     end
49   end
50 end