Mongo to Postgres migration

This PR covers all the necessary changes to make the app work with Postgres. It also includes an upgrade to Rails 4.0.4 from 3.2.17.