diff --git a/libraries/drivers_framework_rails.rb b/libraries/drivers_framework_rails.rb index 59b2b154..f39c15a3 100644 --- a/libraries/drivers_framework_rails.rb +++ b/libraries/drivers_framework_rails.rb @@ -38,8 +38,12 @@ def database_yml(db_driver) database = db_driver.out deploy_environment = deploy_env - replica_db_settings = node['deploy'][app['shortname']]['replica_db_settings'] - database[:replica] = replica_db_settings unless replica_db_settings.nil? + + # this will ensure that replica settings are available in the database.yml file so that + # staging and production database settings have similar settings + replica_database = node['deploy'][app['shortname']]['replica_db_settings']&.dup + replica_database = database.dup if replica_database.nil? + replica_database[:replica] = true factory_database = node['deploy'][app['shortname']]['factory_database'] @@ -50,6 +54,7 @@ def database_yml(db_driver) group www_group variables( database: database, + replica: replica_database, environment: deploy_environment, factory_database: factory_database ) diff --git a/templates/default/database.yml.erb b/templates/default/database.yml.erb index 01a1e1be..edada92e 100644 --- a/templates/default/database.yml.erb +++ b/templates/default/database.yml.erb @@ -1,7 +1,10 @@ <%= config = {} (['development', 'production'] + Array.wrap(@environment)).select(&:present?).uniq.each do |env| - config[env] = @database + config[env] = { + primary: @database, + primary_replica: @replica + } end if @factory_database