Read database.yml from a migration

I need to know which environment and database my migration is running
for.

I can read RAILS_ENV

How do I lookup my environment in database.yml?

Thanks for any help

Desert P. wrote:

I need to know which environment and database my migration is running
for.

I can read RAILS_ENV

How do I lookup my environment in database.yml?

Thanks for any help

I figured it out:

y = 

YAML::load(ERB.new((IO.read("#{RAILS_ROOT}/config/database.yml"))).result)
db = y[RAILS_ENV][“database”]

ActiveRecord::Base.configurations also already has what you seek loaded.

  • Gabriel

Gabriel Gironda wrote:

ActiveRecord::Base.configurations also already has what you seek loaded.

  • Gabriel

Thanks for the tip - can you post an example for this?

I can’t seem to find any documentation after googling…

Thanks

On May 23, 7:02 am, Desert P. [email protected]
wrote:

Gabriel Gironda wrote:

ActiveRecord::Base.configurations also already has what you seek loaded.

  • Gabriel

Thanks for the tip - can you post an example for this?

I can’t seem to find any documentation after googling…

console is your best friend in such cases
just give it
ActiveRecord::Base.configurations