Skip to content

Instantly share code, notes, and snippets.

@jnf
Last active December 11, 2015 11:38
Show Gist options
  • Save jnf/4594938 to your computer and use it in GitHub Desktop.
Save jnf/4594938 to your computer and use it in GitHub Desktop.
Example rake task to generate ~/.pgpass based on info fetched from 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
@ninjapanzer
Copy link

I was unaware of the usefulness of the grave ` when using commands like this. Very cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment