docbrown/docs/additional-postgres-setup.md
rhymes ae3e0b4e8e Expand documentation on how to connect to PostgreSQL (#479)
* Expand documentation on how to connect to PostgreSQL

* Add link to Rails guides and PostgreSQL connection strings

* Expand warning wording
2018-08-28 15:56:31 -04:00

2.5 KiB

Setup your application with PostgreSQL

Follow the instructions in the installation guide below that corresponds to your operating system:

  1. macOS
    • Postgres.app: PostgreSQL installation as a Mac app
    • Homebrew: if you use Homebrew you can easily install PostgreSQL with brew install postgresql
  2. Linux (Ubuntu)
  3. Windows

You can find all installation options for a variety of operating systems on the official PostgreSQL download page.

Configuration

By default the application is configured to connect to a local database named PracticalDeveloper_development. If you need to specify a username and a password you can go about it two ways: using the environment variable DATABASE_URL with a connection string (preferred method) or modifying the file database.yml.

The official Rails guides go into depth on how Rails merges the existing database.yml with the connection string.

Setup DATABASE_URL in application.yml

  1. Open your config/application.yml

  2. Add the following:

DATABASE_URL: postgresql://USERNAME:PASSWORD@localhost/PracticalDeveloper_development
  1. Replace USERNAME with your database username, PASSWORD with your database password.

You can find more details on connection strings in PostgreSQL's own documentation.

Modify connection params in database.yml

The other option is to change the database.yml directly.

Update your database.yml file with username and password:

development:
    <<: *default
    username: USERNAME
    password: PASSWORD
test:
    <<: *default
    username: USERNAME
    password: PASSWORD

Keep in mind not to commit your modified database.yml containing your credentials under any circumstances to any repository.

Troubleshooting tests

  • While running test cases, if you get an error message postgresql connection timeout. Go to your spec/support/database_cleaner.rb file. And rename :truncation with :deletion.

Please, do not commit database_cleaner.rb to the repository either.