Last active
December 11, 2015 11:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was unaware of the usefulness of the grave ` when using commands like this. Very cool