Skip to content

Instantly share code, notes, and snippets.

@lucasprag
Forked from gullitmiranda/database.yml
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save lucasprag/a6f1fb4f3155b5423bba to your computer and use it in GitHub Desktop.

Select an option

Save lucasprag/a6f1fb4f3155b5423bba to your computer and use it in GitHub Desktop.

Revisions

  1. @gullitmiranda gullitmiranda revised this gist Apr 28, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions database.yml
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,11 @@ rescue URI::InvalidURIError
    raise "Invalid DATABASE_URL"
    end
    raise "No RACK_ENV or RAILS_ENV found" unless ENV["RAILS_ENV"] || ENV["RACK_ENV"]
    env = ENV["RAILS_ENV"] || ENV["RACK_ENV"]
    raise "No RACK_ENV or RAILS_ENV found" unless env
    def attribute(name, value, force_string = false)
    if value
    value_string =
    @@ -43,7 +44,7 @@ adapter = case uri.scheme.to_s
    end
    %>

    <%= ENV["RAILS_ENV"] || ENV["RACK_ENV"] %>:
    <%= env %>:
    <%= attribute "adapter", adapter %>
    <%= attribute "database", database %>
    <%= attribute "username", username %>
    @@ -53,4 +54,4 @@ adapter = case uri.scheme.to_s

    <% params.each do |key, value| %>
    <%= key %>: <%= value.first %>
    <% end %>
    <% end %>
  2. @gullitmiranda gullitmiranda revised this gist Apr 28, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion database.yml
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ end
    raise "No RACK_ENV or RAILS_ENV found" unless ENV["RAILS_ENV"] || ENV["RACK_ENV"]
    env = ENV["RAILS_ENV"] || ENV["RACK_ENV"]
    def attribute(name, value, force_string = false)
    if value
    value_string =
    @@ -24,7 +26,7 @@ def attribute(name, value, force_string = false)
    end
    end
    database = "#{(uri.path || "").split("/")[1]}_#{ENV['RAILS_ENV']}"
    database = "#{(uri.path || "").split("/")[1]}_#{env}"
    username = uri.user
    password = uri.password
    host = uri.host
  3. @gullitmiranda gullitmiranda revised this gist Apr 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion database.yml
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ def attribute(name, value, force_string = false)
    end
    end
    database = "#{(uri.path || "").split("/")[1]}_#{RAILS_ENV}"
    database = "#{(uri.path || "").split("/")[1]}_#{ENV['RAILS_ENV']}"
    username = uri.user
    password = uri.password
    host = uri.host
  4. @gullitmiranda gullitmiranda revised this gist Apr 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion database.yml
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ def attribute(name, value, force_string = false)
    end
    end
    database = (uri.path || "").split("/")[1]
    database = "#{(uri.path || "").split("/")[1]}_#{RAILS_ENV}"
    username = uri.user
    password = uri.password
    host = uri.host
  5. @gullitmiranda gullitmiranda created this gist Nov 18, 2014.
    54 changes: 54 additions & 0 deletions database.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    <%
    require 'cgi'
    require 'uri'
    begin
    uri = URI.parse(ENV["DATABASE_URL"])
    rescue URI::InvalidURIError
    raise "Invalid DATABASE_URL"
    end
    raise "No RACK_ENV or RAILS_ENV found" unless ENV["RAILS_ENV"] || ENV["RACK_ENV"]
    def attribute(name, value, force_string = false)
    if value
    value_string =
    if force_string
    '"' + value + '"'
    else
    value
    end
    "#{name}: #{value_string}"
    else
    ""
    end
    end
    database = (uri.path || "").split("/")[1]
    username = uri.user
    password = uri.password
    host = uri.host
    port = uri.port
    params = CGI.parse(uri.query || "")
    params["encoding"] = ["utf8"] unless params["encoding"].present?
    params["pool" ] = [5] unless params["pool" ].present?
    adapter = case uri.scheme.to_s
    when "postgres" then "postgresql"
    when "mysql" then "mysql2"
    else uri.scheme.to_s
    end
    %>

    <%= ENV["RAILS_ENV"] || ENV["RACK_ENV"] %>:
    <%= attribute "adapter", adapter %>
    <%= attribute "database", database %>
    <%= attribute "username", username %>
    <%= attribute "password", password, true %>
    <%= attribute "host", host %>
    <%= attribute "port", port %>

    <% params.each do |key, value| %>
    <%= key %>: <%= value.first %>
    <% end %>