Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active January 31, 2017 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmervine/8524df314c49714c7de923d447e9a0a5 to your computer and use it in GitHub Desktop.
Save jmervine/8524df314c49714c7de923d447e9a0a5 to your computer and use it in GitHub Desktop.
unless ENV['DATABASE_URL'].present?
# convert current config/database.yml to ENV['DATABASE_URL'] format
c = ActiveRecord::Base.configurations[Rails.env]
database = c["database"]
username = c["username"]
password = c["password"]
adapter = c["adapter"] || "postgres"
hostname = c["host"] || "localhost"
ENV['DATABASE_URL'] = [
adapter,
"://",
(username ? "#{username}:" : ""),
(username && password ? password : ""),
(username ? "@" : ""),
hostname,
"/",
database
].join("")
end
@jmervine
Copy link
Author

@tobin Hoping to never actually need this, but worth sharing incase. =P

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