BUGFIX: make sure we can access db config hash with either strings or symbols

This commit is contained in:
Régis Hanol 2014-02-20 19:11:43 +01:00
parent 1f90f3044f
commit 918af0c6ee

View file

@ -104,15 +104,15 @@ module BackupRestore
DatabaseConfiguration = Struct.new(:host, :username, :password, :database) DatabaseConfiguration = Struct.new(:host, :username, :password, :database)
def self.database_configuration def self.database_configuration
if Rails.env.production? config = Rails.env.production? ? ActiveRecord::Base.connection_pool.spec.config : Rails.configuration.database_configuration[Rails.env]
db = ActiveRecord::Base.connection_pool.spec.config config = config.with_indifferent_access
db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"])
else DatabaseConfiguration.new(
db = Rails.configuration.database_configuration[Rails.env] config["host"],
db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"]) config["username"] || ENV["USER"] || "postgres",
end config["password"],
db_conf.username ||= ENV["USER"] || "postgres" config["database"]
db_conf )
end end
private private