Sha256: 3112ae61ee473f69d17c71fafb8216c956e38ac9895252d54c04543975d7670d

Contents?: true

Size: 909 Bytes

Versions: 1

Compression:

Stored size: 909 Bytes

Contents

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
      if defined?(ActiveRecord::Base)
        ActiveRecord::Base.configurations
      else
        YAML.load_file("config/database.yml")
      end
    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wcc-base-0.2.1 lib/tasks/db.rake