gitlab-org--gitlab-foss/db/migrate/20140907220153_serialize_se...

44 lines
1.5 KiB
Ruby
Raw Normal View History

# rubocop:disable all
class SerializeServiceProperties < ActiveRecord::Migration[4.2]
2014-09-08 00:54:18 +00:00
def change
2015-02-24 01:56:05 +00:00
unless column_exists?(:services, :properties)
add_column :services, :properties, :text
end
2014-09-11 15:48:29 +00:00
Service.reset_column_information
2014-09-08 00:54:18 +00:00
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],
2014-09-11 15:48:29 +00:00
JenkinsService: [:project_url],
2014-09-08 00:54:18 +00:00
JiraService: [:project_url, :username, :password,
:api_version, :jira_issue_transition_id],
}
2015-02-24 01:56:05 +00:00
Service.find_each(batch_size: 500).each do |service|
2014-09-08 00:54:18 +00:00
associations[service.type.to_sym].each do |attribute|
service.send("#{attribute}=", service.attributes[attribute.to_s])
end
2015-02-24 01:56:05 +00:00
service.save(validate: false)
2014-09-08 00:54:18 +00:00
end
2015-02-24 01:56:05 +00:00
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
2014-09-08 00:54:18 +00:00
end
end