Sha256: 5c0a7a2bfd024c8c26cdfaa9944d77367eb1ca9e59f6944fd0f5984374d9edb8

Contents?: true

Size: 1.59 KB

Versions: 67

Compression:

Stored size: 1.59 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').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').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

67 entries across 67 versions & 1 rubygems

Version Path
foreman_remote_execution-10.1.3 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-11.1.3 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.1.2 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.1.1 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-11.1.1 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-11.1.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.1.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-8.3.3 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-8.3.2 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-11.0.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.7 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-8.3.1 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.6 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.5 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.4 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.3 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.2 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.1 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-10.0.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb
foreman_remote_execution-8.3.0 db/migrate/20200623073022_rename_sudo_password_to_effective_user_password.rb