Can you get DB username, pw, database name in Rails?

前端 未结 5 1903
感动是毒
感动是毒 2020-12-12 11:54

I\'m writing a rake task that does some DB work outside of Rails/ActiveRecord.

Is there a way to get the DB connection info (host, username, password, DB name) for t

5条回答
  •  清歌不尽
    2020-12-12 12:04

    I think this is the simplest solution. After some testing (in Rails 5.2 at least) this will resolve DATABASE_URL correctly.

     ActiveRecord::Base.configurations[Rails.env]
    

提交回复
热议问题