If you’ve played around with Ruby on Rails, you might have noticed that Rails comes with SQLite3 as your test / development database, while Heroku defaults to PostgreSQL in production.
This is not surprising, considering how hard it is to install PostgreSQL compared to SQLite3. However, since you’re not testing / developing in completely the same environment as production, you’re putting yourself in a position for some possibly nasty surprises (in case you can’t tell, I’ve definitely faced these already, even with my small apps!).
Luckily, there is now a simpler way to install and configure PostgreSQL if you haven’t ever downloaded it on your Mac before brought you by Ruby on Rails developer Gavin Morgan:
Here are the steps to follow to get PostgreSQL downloaded and running with your Rails application:
- Visit postgresapp.com & download the app.
- Install & run the app.
- Execute “$ psql -h localhost” to enter local psql terminal.
- Execute “=# select * from pg_roles;” to list the accounts w/ access privelages.
- Execute “$ rails new myApp -d postgresql” to create psql rails app.
- Fix config/database.yml to include your psql credentials — ‘username‘and ‘password’ (you can leave the password blank if you don’t remember it).
- Fit ‘host: localhost‘ into config/database.yml under ‘test:’ & ‘development:‘
- Note: Heroku is gonna throw database.yml away & use its own settings.
- Execute “$ rake db:create:all” to create your psql databases.
Note: If you have installed PostgreSQL before via ‘$brew install postgresql’ and it’s not working for you, find someone more experienced to help you make it work. Today, I got help from bloc.io co-founder Dave Paolo, who performed a lot of magic and sorcery to delete the installed version of PostgreSQL from my machine so I can re-download it!