From dcfb990e1bd56df44595782bd0fe356e6c8f2c76 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 14 Mar 2012 11:31:38 -0700 Subject: [PATCH] Move database configuration section from Getting Started Guide into Configuration guide This is because newbies don't need to know immediately all the different ways of configuring a database on Rails. The default is SQLite3 which'll work on most operating systems by default. The only reason for it to *not* work is due to missing packages on the operating system, which should be taken care of in some sort of 'Installing Rails for guide. --- railties/guides/source/configuring.textile | 93 ++++++++++++ .../guides/source/getting_started.textile | 140 ------------------ 2 files changed, 93 insertions(+), 140 deletions(-) diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index d6e500fc4b..28d198c00b 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -467,6 +467,99 @@ There are a few configuration options available in Active Support: * +ActiveSupport::Logger.silencer+ is set to +false+ to disable the ability to silence logging in a block. The default is +true+. +h4. Configuring a Database + +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: + +* The +development+ environment is used on your development/local computer as you interact manually with the application. +* The +test+ environment is used when running automated tests. +* The +production+ environment is used when you deploy your application for the world to use. + +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. + +h5. Configuring an SQLite3 Database + +Rails comes with built-in support for "SQLite3":http://www.sqlite.org, which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing. Rails defaults to using an SQLite database when creating a new project, but you can always change it later. + +Here's the section of the default configuration file (config/database.yml) with connection information for the development environment: + + +development: + adapter: sqlite3 + database: db/development.sqlite3 + pool: 5 + timeout: 5000 + + +NOTE: Rails uses an SQLite3 database for data storage by default because it is a zero configuration database that just works. Rails also supports MySQL and PostgreSQL "out of the box", and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it. + +h5. Configuring a MySQL Database + +If you choose to use MySQL instead of the shipped SQLite3 database, your +config/database.yml+ will look a little different. Here's the development section: + + +development: + adapter: mysql2 + encoding: utf8 + database: blog_development + pool: 5 + username: root + password: + socket: /tmp/mysql.sock + + +If your development computer's MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the +development+ section as appropriate. + +h5. Configuring a PostgreSQL Database + +If you choose to use PostgreSQL, your +config/database.yml+ will be customized to use PostgreSQL databases: + + +development: + adapter: postgresql + encoding: unicode + database: blog_development + pool: 5 + username: blog + password: + + +h5. Configuring an SQLite3 Database for JRuby Platform + +If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: + + +development: + adapter: jdbcsqlite3 + database: db/development.sqlite3 + + +h5. Configuring a MySQL Database for JRuby Platform + +If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: + + +development: + adapter: jdbcmysql + database: blog_development + username: root + password: + + +h5. Configuring a PostgreSQL Database for JRuby Platform + +If you choose to use PostgreSQL and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: + + +development: + adapter: jdbcpostgresql + encoding: unicode + database: blog_development + username: blog + password: + + +Change the username and password in the +development+ section as appropriate. h3. Rails Environment Settings diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index bed14ef6a8..dd1dd55f56 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -292,146 +292,6 @@ rundown on the function of each of the files and folders that Rails created by d |tmp/|Temporary files| |vendor/|A place for all third-party code. In a typical Rails application, this includes Ruby Gems and the Rails source code (if you optionally install it into your project).| -h4. Configuring a Database - -Just about every Rails application will interact with a database. The database -to use is specified in a configuration file, +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: - -* The +development+ environment is used on your development/local computer as you interact -manually with the application. -* The +test+ environment is used when running automated tests. -* The +production+ environment is used when you deploy your application for the world to use. - -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. - -h5. Configuring an SQLite3 Database - -Rails comes with built-in support for "SQLite3":http://www.sqlite.org, which is -a lightweight serverless database application. While a busy production -environment may overload SQLite, it works well for development and testing. -Rails defaults to using an SQLite database when creating a new project, but you -can always change it later. - -Here's the section of the default configuration file -(config/database.yml) with connection information for the development -environment: - - -development: - adapter: sqlite3 - database: db/development.sqlite3 - pool: 5 - timeout: 5000 - - -NOTE: In this guide we are using an SQLite3 database for data storage, because -it is a zero configuration database that just works. Rails also supports MySQL -and PostgreSQL "out of the box", and has plugins for many database systems. If -you are using a database in a production environment Rails most likely has an -adapter for it. - -h5. Configuring a MySQL Database - -If you choose to use MySQL instead of the shipped SQLite3 database, your -+config/database.yml+ will look a little different. Here's the development -section: - - -development: - adapter: mysql2 - encoding: utf8 - database: blog_development - pool: 5 - username: root - password: - socket: /tmp/mysql.sock - - -If your development computer's MySQL installation includes a root user with an -empty password, this configuration should work for you. Otherwise, change the -username and password in the +development+ section as appropriate. - -h5. Configuring a PostgreSQL Database - -If you choose to use PostgreSQL, your +config/database.yml+ will be customized -to use PostgreSQL databases: - - -development: - adapter: postgresql - encoding: unicode - database: blog_development - pool: 5 - username: blog - password: - - -h5. Configuring an SQLite3 Database for JRuby Platform - -If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will -look a little different. Here's the development section: - - -development: - adapter: jdbcsqlite3 - database: db/development.sqlite3 - - -h5. Configuring a MySQL Database for JRuby Platform - -If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look -a little different. Here's the development section: - - -development: - adapter: jdbcmysql - database: blog_development - username: root - password: - - -h5. Configuring a PostgreSQL Database for JRuby Platform - -Finally if you choose to use PostgreSQL and are using JRuby, your -+config/database.yml+ will look a little different. Here's the development -section: - - -development: - adapter: jdbcpostgresql - encoding: unicode - database: blog_development - username: blog - password: - - -Change the username and password in the +development+ section as appropriate. - -h4. Creating the Database - -Now that you have your database configured, it's time to have Rails create an -empty database for you. You can do this by running a rake command: - - -$ rake db:create - - -This will create your development and test SQLite3 databases inside the -db/ folder. - -TIP: Rake is a general-purpose command-runner that Rails uses for many things. -You can see the list of available rake commands in your application by running -+rake -T+. - h3. Hello, Rails! One of the traditional places to start with a new language is by getting some -- GitLab