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)
def self.database_configuration
if Rails.env.production?
db = ActiveRecord::Base.connection_pool.spec.config
db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"])
else
db = Rails.configuration.database_configuration[Rails.env]
db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"])
end
db_conf.username ||= ENV["USER"] || "postgres"
db_conf
config = Rails.env.production? ? ActiveRecord::Base.connection_pool.spec.config : Rails.configuration.database_configuration[Rails.env]
config = config.with_indifferent_access
DatabaseConfiguration.new(
config["host"],
config["username"] || ENV["USER"] || "postgres",
config["password"],
config["database"]
)
end
private