0

I've just made my first ruby on rails app and want to change my database to postgresql in order to use it with heroku. So far I've done this, but I think it's not working correctly. Can you please tell me if you see anything wrong? Thanks

database.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: postgresql
  database: myrubyblog
  user: myrubyblog
  password: 
  pool: 5
  timeout: 5000

development:
  <<: *default
  adapter: postgresql
  database: myrubyblog
  user: myrubyblog
  password: 

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  adapter: postgresql
  database: myrubyblog
  user: myrubyblog
  password: 

production:
  <<: *default
  adapter: postgresql
  database: myrubyblog
  user: myrubyblog
  password: 

I've also changed gem 'sqlite3' into gem 'pg' in Gemfile

Miha Šušteršič
  • 9,742
  • 25
  • 92
  • 163

2 Answers2

4

The following should work (assuming the user & password are correct in postgres)

default: &default
  adapter: postgresql
  user: myrubyblog
  password: 
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: myrubyblog

test:
  <<: *default
  database: myrubyblog

See What do the &,<<, * mean in this database.yml file? for how &default is re-used for each of the database definitions.

You don't need to define a production env in your database.yml; heroku will create its own version of database.yml for use in production.

See http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database for more details about the configuration in database.yml

Running rails new myblogapp --database=postgresql will create a new myblogapp application with the appropriate content in database.yml customized for using with postgres.

Community
  • 1
  • 1
Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
-1

It appears to depend on your Rails version. Heroku gives instructions here:

https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-ruby