OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/db/migrate/20190920102446_clean_custom...

23 lines
699 B

class CleanCustomValues < ActiveRecord::Migration[5.2]
def up
invalid_cv = CustomValue
.joins(:custom_field)
.where("#{CustomField.table_name}.field_format = 'list'")
.where.not(value: '')
.where("value !~ '^[0-9]+$'")
if invalid_cv.count > 0
warn_string = "Replacing invalid list custom values:\n"
invalid_cv.pluck(:customized_type, :customized_id, :value).each do |customized_type, customized_id, value|
warn_string << "- #{customized_type} ##{customized_id}: Value was #{value.inspect}\n"
end
warn warn_string
invalid_cv.update_all(value: '')
end
end
def down
# This migration does not restore data
end
end