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

Version Path
foreman_remote_execution-9.1.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-8.2.1 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-8.2.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-9.0.1 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-9.0.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-8.1.2 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-8.1.1 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-8.1.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-7.2.2 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-7.2.1 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-7.2.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-5.0.8 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-8.0.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-7.1.1 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-7.1.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-7.0.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-5.0.7 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-5.0.6 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-6.2.0 db/migrate/20160125155108_make_job_template_name_unique.rb
foreman_remote_execution-5.0.5 db/migrate/20160125155108_make_job_template_name_unique.rb