GitHub PullRequestReviewCommentEvent at 2014-01-09 17:44:46
Repository: rails
Actor: robin850
Payload: {"comment":{"url":"https://api.github.com/repos/rails/rails/pulls/comments/8764239","id":8764239,"diff_hunk":"@@ -455,14 +455,133 @@ There are a few configuration options available in Active Support:\n \n ### Configuring a Database\n \n-Just about every Rails application will interact with a database. The database to use is specified in a configuration file called `config/database.yml`. If you open this file in a new Rails application, you'll see a default database configured to use SQLite3. The file contains sections for three different environments in which Rails can run by default:\n+Just about every Rails application will interact with a database. You can connect to the database by setting an environment variable `ENV['DATABASE_URL']` or by using a configuration file called `config/database.yml`.\n+\n+Using the `config/database.yml` file you can specify all the information needed to access your database:\n+\n+```yaml\n+development:\n+  adapter: postgresql\n+  database: blog_development\n+  pool: 5\n+```\n+\n+This will connect to the database named `blog_development` using the `postgresql` adapter. This same information can be stored in a URL and provided via an environment variable like this:\n+\n+```ruby\n+> puts ENV['DATABASE_URL']\n+postgresql://localhost/blog_development?pool=5\n+```\n+\n+The `config/database.yml` file contains sections for three different environments in which Rails can run by default:\n \n * The `development` environment is used on your development/local computer as you interact manually with the application.\n * The `test` environment is used when running automated tests.\n * The `production` environment is used when you deploy your application for the world to use.\n \n+If you wish, you can manually specify a URL inside of your `config/database.yml`\n+\n+```\n+development:\n+  url: postgresql://localhost/blog_development?pool=5\n+```\n+\n+The `config/database.yml` file can contain ERB tags `<%= %>`. Anything in the tags will be evaluated as Ruby code. You can use this to pull out data from an environment variable or to perform calculations to generate the needed connection information.\n+\n+\n TIP: You don't have to update the database configurations manually. If you look at the options of the application generator, you will see that one of the options is named `--database`. This option allows you to choose an adapter from a list of the most used relational databases. You can even run the generator repeatedly: `cd .. && rails new blog --database=mysql`. When you confirm the overwriting of the `config/database.yml` file, your application will be configured for MySQL instead of SQLite. Detailed examples of the common database connections are below.\n \n+\n+### Connection Preference\n+\n+Since there are two ways to set your connection, via environment variable it is important to understand how the two can interact.\n+\n+If you have an empty `config/database.yml` file but your `ENV['DATABASE_URL']` is present, then Rails will connect to the database in your environment variable:\n+\n+```\n+$ cat config/database.yml\n+\n+$ echo $DATABASE_URL\n+postgresql://localhost/my_database\n+```\n+\n+If you have a `config/database.yml` but no `ENV['DATABASE_URL']` then this file will be used to connect to your database:\n+\n+```\n+$ cat config/database.yml\n+development:\n+  adapter: postgresql\n+  database: my_database\n+  host: localhost\n+\n+$ echo $DATABASE_URL\n+```\n+\n+If you have both `config/database.yml` and `ENV['DATABASE_URL']` set then Rails will merge the configuration together. To better understand this we must see some examples.\n+","path":"guides/source/configuring.md","position":68,"original_position":68,"commit_id":"5580fdbe497301f4f45fe1289410b2c3a363e08d","original_commit_id":"5580fdbe497301f4f45fe1289410b2c3a363e08d","user":{"login":"robin850","id":354185,"avatar_url":"https://gravatar.com/avatar/2d27b53e2eeb6a053552332020628029?d=https%3A%2F%2Fidenticons.github.com%2Fafc5fd60924eb324ae549e95c93f0643.png&r=x","gravatar_id":"2d27b53e2eeb6a053552332020628029","url":"https://api.github.com/users/robin850","html_url":"https://github.com/robin850","followers_url":"https://api.github.com/users/robin850/followers","following_url":"https://api.github.com/users/robin850/following{/other_user}","gists_url":"https://api.github.com/users/robin850/gists{/gist_id}","starred_url":"https://api.github.com/users/robin850/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robin850/subscriptions","organizations_url":"https://api.github.com/users/robin850/orgs","repos_url":"https://api.github.com/users/robin850/repos","events_url":"https://api.github.com/users/robin850/events{/privacy}","received_events_url":"https://api.github.com/users/robin850/received_events","type":"User","site_admin":false},"body":":scissors:","created_at":"2014-01-09T17:44:46Z","updated_at":"2014-01-09T17:44:46Z","html_url":"https://github.com/rails/rails/pull/13582#discussion_r8764239","pull_request_url":"https://api.github.com/repos/rails/rails/pulls/13582","_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/8764239"},"html":{"href":"https://github.com/rails/rails/pull/13582#discussion_r8764239"},"pull_request":{"href":"https://api.github.com/repos/rails/rails/pulls/13582"}}}}