module ActiveRecord::ConnectionHandling

def establish_connection(config_or_env = nil)

may be returned on an error.
The exceptions AdapterNotSpecified, AdapterNotFound, and +ArgumentError+

ActiveRecord::Base.establish_connection(:production)

configuration hash:
a symbol can also be given as argument, representing a key in the
is set (Rails automatically loads the contents of config/database.yml into it),
In case {ActiveRecord::Base.configurations}[rdoc-ref:Core.configurations]

)
"postgres://myuser:mypass@localhost/somedatabase"
ActiveRecord::Base.establish_connection(

Or a URL:

)
"database" => "path/to/dbfile"
"adapter" => "sqlite3",
ActiveRecord::Base.establish_connection(

Also accepts keys as strings (for parsing from YAML for example):

)
database: "path/to/dbfile"
adapter: "sqlite3",
ActiveRecord::Base.establish_connection(

Example for SQLite database:

)
database: "somedatabase"
password: "mypass",
username: "myuser",
host: "localhost",
adapter: "mysql2",
ActiveRecord::Base.establish_connection(

example for regular databases (MySQL, PostgreSQL, etc):
the :adapter key must be specified with the name of a database adapter (in lower-case)
Establishes the connection to the database. Accepts a hash as input where
def establish_connection(config_or_env = nil)
  config_or_env ||= DEFAULT_ENV.call.to_sym
  db_config, owner_name = resolve_config_for_connection(config_or_env)
  connection_handler.establish_connection(db_config, owner_name: owner_name, role: current_role, shard: current_shard)
end