Skip to content

Commit eab03cf

Browse files
ikirifqiMassimilianoLattanzio
authored andcommitted
Add database primary replica configuration
1 parent 608a8db commit eab03cf

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

libraries/drivers_framework_rails.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ def database_yml(db_driver)
3838

3939
database = db_driver.out
4040
deploy_environment = deploy_env
41-
replica_db_settings = node['deploy'][app['shortname']]['replica_db_settings']
42-
database[:replica] = replica_db_settings unless replica_db_settings.nil?
41+
42+
# this will ensure that replica settings are available in the database.yml file so that
43+
# staging and production database settings have similar settings
44+
replica_database = node['deploy'][app['shortname']]['replica_db_settings']&.dup
45+
replica_database = database.dup if replica_database.nil?
46+
replica_database[:replica] = true
4347

4448
factory_database = node['deploy'][app['shortname']]['factory_database']
4549

@@ -50,6 +54,7 @@ def database_yml(db_driver)
5054
group www_group
5155
variables(
5256
database: database,
57+
replica: replica_database,
5358
environment: deploy_environment,
5459
factory_database: factory_database
5560
)

templates/default/database.yml.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<%=
22
config = {}
33
(['development', 'production'] + Array.wrap(@environment)).select(&:present?).uniq.each do |env|
4-
config[env] = @database
4+
config[env] = {
5+
primary: @database,
6+
primary_replica: @replica
7+
}
58
end
69

710
if @factory_database

0 commit comments

Comments
 (0)