Sha256: fd2114b3c45e1b0bf6c6716a2985bb0cb99feabe6b5863883320a0983f97f9e9

Contents?: true

Size: 738 Bytes

Versions: 36

Compression:

Stored size: 738 Bytes

Contents

class AddUniquenessToPuppetclassName < ActiveRecord::Migration[5.1]
  class FakePuppetclass < ApplicationRecord
    self.table_name = 'puppetclasses'
  end

  def up
    names = FakePuppetclass.group(:name).count.select { |_key, value| value > 1 }.keys
    unless names.empty?
      names.each do |name|
        classes = FakePuppetclass.where name: name
        say "#{classes.count} Puppet classes with duplicate name detected: #{name}"
      end
      raise 'Please make sure there are no duplicate Puppet classes before continuing.'
    end

    remove_index :puppetclasses, :name
    add_index :puppetclasses, :name, unique: true
  end

  def down
    remove_index :puppetclasses, :name
    add_index :puppetclasses, :name
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
foreman_puppet-8.0.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-6.4.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-7.0.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-6.3.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-6.2.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-6.1.1 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-5.1.3 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-6.1.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-6.0.1 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-6.0.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-5.1.2 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-4.1.1 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-5.1.1 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-5.1.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-4.1.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-4.0.4 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-5.0.0 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-4.0.3 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-4.0.2 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb
foreman_puppet-3.0.7 db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb