Insomnia

Rails / PostgreSQL tips

I have been switching between Sqlite and PosgreSQL for my Rails applications. Considering how easy it’s been to move a sqlite3 dev database to Heroku hosted PostgreSQL, I haven’t had much need for PostgreSQL lately. However, I’d like to avoid any surprises because of DB-specific SQL.

So, I just created a Rails/PostgreSQL app, and am documenting the steps for posterity.

  1. Create a Rails app with ‘rails new myapp -d postgresql’
  2. Create database
    • If you haven’t already created a user yet, look at this page Setup Rails
    • Note: That creates a role in template1 (Read up on templates in PostgreSQL if you’re not familiar
    • Create the databases, either with DDL, like in the previou link, or from the shell like in this example (Create Database)
  3. Modify config/database.yml with the username/password that you just created
  4. Then run ‘bundle exec rake db:migrate’