Rails Starter config/database.rb with PostgreSQL

Primespot Engineering - May 26, 2020

EngineeringRails

When starting a new Rails project, an early stumbling block for me is setting up the database. I always find myself going back to an old project to remind myself of the config format.

After you figure out the way to structure the file, it’s simple to get working. But until then, I get confused about whether the property is “host” or “hostname”, “user” or “username”, etc.

If you are in the same boat, this starter config.yml file might be of use to you as a reference.

Make sure you replace the magic strings with the correct input for your configuration.

default: &default
   adapter: postgresql
   encoding: unicode
   pool: <%= ENV.fetch("RAILS_MAX_THREADS") 5 %>
   host: localhost
   port: 5432
   username: enter_database_username_here
   password: enter_database_password_here

development:
   <<: *default
   database: project_name_development

test:
   <<: *default
   database: project_name_test

production:
   <<: *default
   database: project_name_production
   username: <%= ENV['PROJECT_DATABASE_USERNAME'] %>
   password: <%= ENV['PROJECT_DATABASE_PASSWORD'] %>

© 2020 Primespot Services. All rights reserved.