Skip to content

Commit

Permalink
Add database primary replica configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ikirifqi committed Oct 11, 2023
1 parent c751e37 commit e92fcaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions libraries/drivers_framework_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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
)
Expand Down
5 changes: 4 additions & 1 deletion templates/default/database.yml.erb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e92fcaa

Please sign in to comment.