Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 998
sam452 Avatar asked Apr 25 '15 20:04

sam452


People also ask

How do I view a rails database?

You can use rails dbconsole to view the database that your rails application is using. It's alternative answer rails db . Both commands will direct you the command line interface and will allow you to use that database query syntax.

What database does rails use?

Rails defaults to using a SQLite database when creating a new project, but you can always change it later.


1 Answers

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.

like image 183
Pramod Shinde Avatar answered Oct 12 '22 22:10

Pramod Shinde