Skip to content

Commit

Permalink
Reimplement a794081
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Dec 13, 2023
1 parent 6027a6a commit e87af10
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class Status
validates :operation, inclusion: { in: Operation.constants.map{ |c| Operation.const_get(c) },
message: "%{value} is not a valid operation" }

# Instances will often be updated from inside transactions, outside of which
# any updates would not be visible. So, we use a different database
# connection.
establish_connection "#{Rails.env}_2".to_sym

##
# @return [String] Console representation of the instance.
#
Expand Down
5 changes: 5 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def self.to_s(status)

before_save :constrain_progress

# Instances will often be updated from inside transactions, outside of which
# any updates would not be visible. So, we use a different database
# connection.
establish_connection "#{Rails.env}_2".to_sym

##
# @return [Time,nil]
#
Expand Down
22 changes: 17 additions & 5 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,44 @@ test_config = File.exist?(path) ? YAML.load(File.read(path)) : {}
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 10 } %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
min_messages: warning
template: template0
query_cache: 1000 # default in Rails 7.1 is 100

development:
development: &development
<<: *default
host: <%= dev_config['primary_db'] ? dev_config['primary_db']['host'] : nil %>
port: <%= dev_config['primary_db'] ? dev_config['primary_db']['port'] : nil %>
database: <%= dev_config['primary_db'] ? dev_config['primary_db']['database'] : nil %>
username: <%= dev_config['primary_db'] ? dev_config['primary_db']['username'] : nil %>
password: <%= dev_config['primary_db'] ? dev_config['primary_db']['password'] : nil %>

development_2:
<<: *development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
test: &test
<<: *default
host: <%= test_config['primary_db'] ? test_config['primary_db']['host'] : nil %>
port: <%= test_config['primary_db'] ? test_config['primary_db']['port'] : nil %>
database: <%= test_config['primary_db'] ? test_config['primary_db']['database'] : nil %>
username: <%= test_config['primary_db'] ? test_config['primary_db']['username'] : nil %>
password: <%= test_config['primary_db'] ? test_config['primary_db']['password'] : nil %>

test_2:
<<: *test

#############################################################################
# ENVIRONMENTS USING ENCRYPTED CONFIG #
#############################################################################

<% db = Rails.application.credentials.dig(:primary_db) %>

demo:
demo: &demo
<<: *default
pool: <%= 2 * ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i %>
host: <%= db ? db[:host] : nil %>
Expand All @@ -62,11 +68,17 @@ demo:
username: <%= db ? db[:username] : nil %>
password: <%= db ? db[:password] : nil%>

production:
demo_2:
<<: *demo

production: &production
<<: *default
pool: <%= 2 * ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i %>
host: <%= db ? db[:host] : nil %>
port: <%= db ? db[:port] : nil %>
database: <%= db ? db[:database] : nil %>
username: <%= db ? db[:username] : nil %>
password: <%= db ? db[:password] : nil %>

production_2:
<<: *production

0 comments on commit e87af10

Please sign in to comment.