Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database.yml configuration options

I would like to know where I can read about valid configuration options for database.yml for ActiveRecord. I know the basic ones like adapter, database, username, password, etc., but I would like to have the full list for each adapter. Where would I find that?

like image 775
moritz Avatar asked Oct 22 '11 17:10

moritz


1 Answers

I found a gist of database.yml examples using mysql, postgres, and sqlite3, and the Rails 3.2 source code for connection adapters provides good insight as well.

Looks to me that the following are the most widely used options:

  • adapter
  • encoding
  • database
  • pool
  • username
  • password
  • socket
  • host
  • port
  • timeout

The Rails 3.2 connection_specification.rb file looks like it simply merges any options you include, so I'd say what options you include are dependant on the database adapter you choose to use (lines 58-74):

def connection_url_to_hash(url) # :nodoc:
  config = URI.parse url
  adapter = config.scheme
  adapter = "postgresql" if adapter == "postgres"
  spec = { :adapter  => adapter,
           :username => config.user,
           :password => config.password,
           :port     => config.port,
           :database => config.path.sub(%r{^/},""),
           :host     => config.host }
  spec.reject!{ |_,value| !value }
  if config.query
    options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys
    spec.merge!(options)
  end
  spec
end
like image 101
robmclarty Avatar answered Sep 25 '22 15:09

robmclarty