Sha256: ef80c197c9076840b2658c2b4b7876998721b8c6e0f4651cdb967c59580a0a2e
Contents?: true
Size: 568 Bytes
Versions: 141
Compression:
Stored size: 568 Bytes
Contents
class MakeJobTemplateNameUnique < ActiveRecord::Migration[4.2] 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
141 entries across 141 versions & 1 rubygems