Commit 24c8381d authored by Marin Jankovski's avatar Marin Jankovski

Merge branch 'improve-services-migration' into 'master'

Make services migration more reliable

Fix for #2045 . I did not use SQL because its hard to convert SQL fields into json with interpolation and without errors. SO I just improved current migration with next:

* skip validation to prevent exception because of new `template` field in validation
* check column for existance before adding them.
  It should allow people who already failed this migration to re-run ti
* select objects with 500 batch size for better memory usage

Tested on migration from 7.0 to 7.9.0.pre

See merge request !1581
parents 14117c23 0f6221e7
class SerializeServiceProperties < ActiveRecord::Migration
def change
add_column :services, :properties, :text
unless column_exists?(:services, :properties)
add_column :services, :properties, :text
end
Service.reset_column_information
associations =
......@@ -19,18 +22,21 @@ class SerializeServiceProperties < ActiveRecord::Migration
:api_version, :jira_issue_transition_id],
}
Service.all.each do |service|
Service.find_each(batch_size: 500).each do |service|
associations[service.type.to_sym].each do |attribute|
service.send("#{attribute}=", service.attributes[attribute.to_s])
end
service.save
service.save(validate: false)
end
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
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
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment