Check to see if we can connect to the db before accessing it
Merge pull request #403 from shekibobo/fix-heroku-precompile

Check to see if we can connect to the db before accessing it. Fixes #396.