Search code examples
postgresqlruby-on-rails-4

How to find database name in rails console


This is odd. In my Rails 4 database.yml I have the following:

development:
  adapter: postgresql
  encoding: unicode
  database: inspector_development
  password: 
  pool: 5

I copied the production database from Heroku and imported it using this form into my local copy of Postgresql

curl -o latest.dump `heroku pgbackups:url --account personal`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U sam -d inspector_development latest.dump

THe result showed the 88 expected users in PGadmin in the inspector_development database on osx. However, even after restarting the rails app, the User table still shows only one user, not the 88 I see in PGadmin.

I've googled for how to determine what Rails sees as the properties of the database name in order to determine where is it finding these non-existent records?

Looking more closely at the User table in PGadmin I see zero columns. Perhaps PGadmin is mistaken? I'm unable to determine where the db Rails is looking for so that I can troubleshoot this, thx, sam


Solution

  • This works in Rails 3 and Rails 4

    ActiveRecord::Base.connection.current_database
    

    But this only works with drivers that have implemented that method. For example, it will not work for SQLite but will work with mysql and postgres.