Last active
January 31, 2017 21:41
-
-
Save jmervine/8524df314c49714c7de923d447e9a0a5 to your computer and use it in GitHub Desktop.
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tobin Hoping to never actually need this, but worth sharing incase. =P