Sha256: 7c59f638a121810cb8bed9533abe7da7cd6d5dd6aad06e845ad07e47288cc0d6

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

module Cloner::Ar
  def ar_conf
    @conf ||= begin
      YAML.load_file(Rails.root.join('config', 'database.yml'))[env_database]
    end
  end

  def env_database
    Rails.env
  end

  def ar_to
    ar_conf['database']
  end

  def ar_r_conf
    @ar_r_conf ||= begin
      do_ssh do |ssh|
        ret = ssh_exec!(ssh, "cat #{e(remote_app_path + '/config/database.yml')}")
        check_ssh_err(ret)
        begin
          res = YAML.load(ret[0])[env_from]
          raise 'no data' if res.blank?
          #res['host'] ||= '127.0.0.1'
        rescue Exception => e
          puts "unable to read remote database.yml for env #{env_from}."
          puts "Remote file contents:"
          puts ret[0]
        end
        res
      end
    end
  end

  def clone_ar
    if ar_conf["adapter"] != ar_r_conf["adapter"]
      puts "Error: ActiveRecord adapter mismatch: local #{ar_conf["adapter"]}, remote #{ar_r_conf["adapter"]}"
      puts "it is not possible to convert from one database to another via this tool."
      exit
    end

    case ar_conf["adapter"]
    when 'postgresql'
      clone_pg
    when 'mysql2'
      clone_my
    else
      puts "unknown activerecord adapter: #{ar_conf["adapter"]}"
      puts "currently supported adapters: mysql2, postgresql"
      exit
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cloner-0.9.2 lib/cloner/ar.rb
cloner-0.9.1 lib/cloner/ar.rb
cloner-0.9.0 lib/cloner/ar.rb