Read database.yml from a migration


#1

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


#2

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”]


#3

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

  • Gabriel

#4

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


#5

On May 23, 7:02 am, Desert P. removed_email_address@domain.invalid
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