Landon Kuhn
Landon Kuhn

Reputation: 78431

Read database.yml from inside ActiveRecord migration

How do I access the contents of database.yml inside an ActiveRecord migration? Specifically, I need the value of the database key for the database being migrated.

Upvotes: 4

Views: 903

Answers (2)

Hemant Kumar
Hemant Kumar

Reputation: 2018

Try ActiveRecord::Base.configurations

Upvotes: 4

Ashwin Phatak
Ashwin Phatak

Reputation: 655

db = YAML.load_file("#{RAILS_ROOT}/config/database.yml")[RAILS_ENV]['database']

Upvotes: 7

Related Questions