Sha256: 5fc749aa4554b2eed024f1a65221d3f451a99e951023a983a6e382bc3dea629b
Contents?: true
Size: 563 Bytes
Versions: 18
Compression:
Stored size: 563 Bytes
Contents
class MakeJobTemplateNameUnique < ActiveRecord::Migration def up duplicates = JobTemplate.unscoped.group(:name).count.delete_if { |_name, value| value == 1 } duplicates.each_key do |duplicated_name| templates = JobTemplate.where(:name => duplicated_name) templates.each_with_index do |template, index| new_name = JobTemplate.exists?(:name => "#{template.name}-#{index}") ? "#{template.name}-#{index}-#{SecureRandom.hex(2)}" : "#{template.name}-#{index}" template.update_attribute(:name, new_name) end end end end
Version data entries
18 entries across 18 versions & 1 rubygems