Sha256: 51586e6e7fa2672460755186f9c88cf1aa6969dd61fbb82614bd0ba593c7e9a8

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require_relative 'utilities'

module Ferry
  class Switcher < Utilities
    def to_new_db_type(which_db_env, switch_to_db_type)
      if ['sqlite', 'postgresql', 'mysql'].include?(switch_to_db_type)
        info = YAML::load(IO.read("config/database.yml"))
        current_db_type = info[which_db_env]["adapter"]
        puts "switching the #{which_db_env} database's adapter"
        puts "current_db_type: #{current_db_type}"
        puts "to_new_db_type: #{switch_to_db_type}"
        if ['postgresql', 'mysql'].include?(switch_to_db_type)
          info[which_db_env]["adapter"] = switch_to_db_type
          puts "switching #{which_db_env} env to #{switch_to_db_type} ... "
          File.open("config/database.yml", "w") {|f| f.write info.to_yaml}
          puts "switched #{which_db_env} env to #{switch_to_db_type} in database.yml"
          call = %x(bundle show ferry).chomp
          %x(chmod 4755 #{call}/script/#{switch_to_db_type}_install.sh)
          %x(#{call}/script/#{switch_to_db_type}_install.sh)
          puts "installed necessary dependencies for #{which_db_env} env to #{switch_to_db_type}"
        elsif switch_to_db_type == 'sqlite'
          puts "#{switch_to_db_type} already installed on mac!"
        else
          puts "#{switch_to_db_type} is currently unsupported"
        end
      else
        puts "#{switch_to_db_type} is currently unsupported or db type does not exist"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ferry-1.1.0 lib/ferry/switcher.rb
ferry-1.0.1 lib/ferry/switcher.rb