BigW Consortium Gitlab

20140907220153_serialize_service_properties.rb 1.47 KB
Newer Older
1
# rubocop:disable all
2 3
class SerializeServiceProperties < ActiveRecord::Migration
  def change
4 5 6 7
    unless column_exists?(:services, :properties)
      add_column :services, :properties, :text
    end

8
    Service.reset_column_information
9 10 11 12 13 14 15 16 17 18 19 20

    associations =
    {
      AssemblaService:        [:token, :subdomain],
      CampfireService:        [:token, :subdomain, :room],
      EmailsOnPushService:    [:recipients],
      FlowdockService:        [:token],
      GemnasiumService:       [:api_key, :token],
      GitlabCiService:        [:token, :project_url],
      HipchatService:         [:token, :room],
      PivotaltrackerService:  [:token],
      SlackService:           [:subdomain, :token, :room],
21
      JenkinsService:         [:project_url],
22 23 24 25
      JiraService:            [:project_url, :username, :password,
                               :api_version, :jira_issue_transition_id],
    }

26
    Service.find_each(batch_size: 500).each do |service|
27 28 29
      associations[service.type.to_sym].each do |attribute|
        service.send("#{attribute}=", service.attributes[attribute.to_s])
      end
30 31

      service.save(validate: false)
32 33
    end

34 35 36 37 38 39 40 41
    if column_exists?(:services, :project_url)
      remove_column :services, :project_url, :string
      remove_column :services, :subdomain, :string
      remove_column :services, :room, :string
      remove_column :services, :recipients, :text
      remove_column :services, :api_key, :string
      remove_column :services, :token, :string
    end
42 43
  end
end