module WCC
  module RakeHelpers

    def self.db_config
      @config ||= YAML.load_file("config/database.yml")[ENV['RAILS_ENV'] || 'development'] || {}
    end

    def self.db_cmd_with_password(cmd, pw)
      `#{db_cmd_with_password_string(cmd, pw)}`
    end

    def self.db_cmd_with_password_string(cmd, pw)
      %{PGPASSWORD="#{pw}" #{cmd.join(" ")}}
    end

    def self.postgresql?
      db_config["adapter"] == "postgresql"
    end

    def self.mysql?
      db_config["adapter"] == "mysql"
    end

  end
end

namespace :db do

  desc "Drops, creates, migrates, seeds dev DB and prepares test DB"
  task :rebuild => ["db:drop", "db:create", "db:migrate", "db:seed", "db:test:prepare"]

end


module WCC
  module RakeHelpers

    def self.db_config
      @config ||= db_config_file_data[ENV['RAILS_ENV'] || 'development'] || {}
    end

    def self.db_cmd_with_password(cmd, pw)
      `#{db_cmd_with_password_string(cmd, pw)}`
    end

    def self.db_cmd_with_password_string(cmd, pw)
      %{PGPASSWORD="#{pw}" #{cmd.join(" ")}}
    end

    def self.postgresql?
      db_config["adapter"] == "postgresql"
    end

    def self.mysql?
      db_config["adapter"] == "mysql"
    end

    def self.db_config_file_data
      YAML.load_file("config/database.yml")
    rescue SystemCallError
      {}
    end

  end
end

namespace :db do

  desc "Drops, creates, migrates, seeds dev DB and prepares test DB"
  task :rebuild => ["db:drop", "db:create", "db:migrate", "db:seed", "db:test:prepare"]

end


Fix bug causing Rake task failure when no DB config
Fix bug causing Rake task failure when no DB config

The entire `rake` command should not fail because some introspection
failed due to a missing file. This was a pretty glaring bug.
