Sha256: f89c50876e1ae9c9481de90917844652b127d7ee8f30e435010da7a90cdcf186

Contents?: true

Size: 1.6 KB

Versions: 24

Compression:

Stored size: 1.6 KB

Contents

class RenameSudoPasswordToEffectiveUserPassword < ActiveRecord::Migration[6.0]
  def up
    rename_column :job_invocations, :sudo_password, :effective_user_password

    Parameter.where(name: 'remote_execution_sudo_password').find_each do |parameter|
      record = Parameter.find_by(type: parameter.type, reference_id: parameter.reference_id, name: "remote_execution_effective_user_password")
      if record.nil?
        parameter.update(name: "remote_execution_effective_user_password")
      end
    end

    return unless (password = Setting.find_by(:name => 'remote_execution_sudo_password').try(:value))

    Setting.find_by(:name => 'remote_execution_effective_user_password').update(value: password)

    Setting.find_by(:name => 'remote_execution_sudo_password').delete
  end

  def down
    rename_column :job_invocations, :effective_user_password, :sudo_password

    Parameter.where(name: 'remote_execution_effective_user_password').find_each do |parameter|
      record = Parameter.find_by(type: parameter.type, reference_id: parameter.reference_id, name: "remote_execution_sudo_password")
      if record.nil?
        parameter.update(name: "remote_execution_sudo_password")
      end
    end

    return unless (password = Setting.find_by(:name => 'remote_execution_effective_user_password').try(:value))

    Setting.create!(name: 'remote_execution_sudo_password', value: password, description: 'Sudo password', category: 'Setting::RemoteExecution', settings_type: 'string', full_name: 'Sudo password',encrypted: true, default: nil)
    Setting.find_by(:name => 'remote_execution_effective_user_password').delete
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
foreman_remote_execution-13.2.7 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-15.0.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.1.4 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.1.3 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.1.2 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.1.1 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.1.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.0.2 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.0.1 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.2.6 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-14.0.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.2.5 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.2.4 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.2.3 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.2.2 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-12.0.7 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.2.1 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.2.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-13.0.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-12.0.5 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb