Sha256: f1f3b1960daedc1777bece50ab228a6d969c3c598328133fec8f024dbe04994d

Contents?: true

Size: 1003 Bytes

Versions: 66

Compression:

Stored size: 1003 Bytes

Contents

class AddPositionToAnsibleRole < ActiveRecord::Migration[6.0]
  def change
    add_column :host_ansible_roles, :position, :integer
    add_column :hostgroup_ansible_roles, :position, :integer

    update_hostgroup_ansible_roles
    update_host_ansible_roles
    change_column_null :host_ansible_roles, :position, false
    change_column_null :hostgroup_ansible_roles, :position, false
  end

  def update_host_ansible_roles
    HostAnsibleRole.all.pluck(:host_id, :id).group_by(&:first).each do |_host_id, role_ids|
      role_ids.each_with_index do |(_host_id, host_role_id), idx|
        HostAnsibleRole.find(host_role_id).update(position: idx + 1)
      end
    end
  end

  def update_hostgroup_ansible_roles
    HostgroupAnsibleRole.all.pluck(:hostgroup_id, :id).group_by(&:first).each do |_hostgroup_id, role_ids|
      role_ids.each_with_index do |(_hostgroup_id, hostgroup_role_id), idx|
        HostgroupAnsibleRole.find(hostgroup_role_id).update(position: idx + 1)
      end
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
foreman_ansible-15.0.3 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-15.0.2 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-15.0.1 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-15.0.0 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-14.2.2 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-14.2.1 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-13.0.7 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-14.2.0 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-14.1.1 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-14.1.0 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-13.0.5 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-14.0.0 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-13.0.4 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-13.0.3 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-13.0.2 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-13.0.1 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-13.0.0 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-12.0.7 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-10.4.4 db/migrate/20210120150019_add_position_to_ansible_role.rb
foreman_ansible-7.1.8 db/migrate/20210120150019_add_position_to_ansible_role.rb