Make sure we are connected before table_exists?

Because otherwise it will bail because it cannot connect to a DB when doing things like precompiling assets.

Test with:

```
env -i GEM_PATH=$GEM_PATH \
       PATH=$PATH \
       DATABASE_URL=postgres://user:pass@127.0.0.1/dbname \
       /bin/sh -c 'bundle exec rake --trace  assets:precompile'
```