Last Updated: February 25, 2016
·
597
· jnf

Rake task to create ~/.pgpass based on heroku:config

namespace :db do
  require 'uri'
  desc "Uses heroku:config for APP to forcefully create ~/.pgpass"
  task :create_pgpass do
    app = ENV['APP'] || 'whatever-your-default-app-is'
    uri = URI(`heroku config:get DATABASE_URL -a #{app}`)
    entry = "*:5432:#{uri.path.gsub /\//, ''}:#{uri.user}:#{uri.password}"
    `echo '#{entry}' > ~/.pgpass; chmod 0600 ~/.pgpass`
  end
end