feat: add read replica support
This commit is contained in:
@@ -54,6 +54,13 @@ POSTGRES_PASSWORD=
|
||||
RAILS_ENV=development
|
||||
# Changes the Postgres query timeout limit. The default is 14 seconds. Modify only when required.
|
||||
# POSTGRES_STATEMENT_TIMEOUT=14s
|
||||
|
||||
# read replica configuration for production
|
||||
# POSTGRES_HOST_RR=postgres_rr
|
||||
# create a new user with readonly permissions
|
||||
# POSTGRES_USERNAME_RR=postgres_readonly
|
||||
# POSTGRES_PASSWORD_RR=
|
||||
|
||||
RAILS_MAX_THREADS=5
|
||||
|
||||
# The email from which all outgoing emails are sent
|
||||
|
||||
@@ -2,6 +2,8 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
include Events::Types
|
||||
self.abstract_class = true
|
||||
|
||||
connects_to database: { writing: :primary, reading: :primary_replica }
|
||||
|
||||
before_validation :validates_column_content_length
|
||||
|
||||
# the models that exposed in email templates through liquid
|
||||
|
||||
+12
-4
@@ -22,7 +22,15 @@ test:
|
||||
password: "<%= ENV.fetch('POSTGRES_PASSWORD', '') %>"
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: "<%= ENV.fetch('POSTGRES_DATABASE', 'chatwoot_production') %>"
|
||||
username: "<%= ENV.fetch('POSTGRES_USERNAME', 'chatwoot_prod') %>"
|
||||
password: "<%= ENV.fetch('POSTGRES_PASSWORD', 'chatwoot_prod') %>"
|
||||
primary:
|
||||
<<: *default
|
||||
database: "<%= ENV.fetch('POSTGRES_DATABASE', 'chatwoot_production') %>"
|
||||
username: "<%= ENV.fetch('POSTGRES_USERNAME', 'chatwoot_prod') %>"
|
||||
password: "<%= ENV.fetch('POSTGRES_PASSWORD', 'chatwoot_prod') %>"
|
||||
primary_replica:
|
||||
<<: *default
|
||||
host: "<%= ENV.fetch('POSTGRES_HOST_RR', 'localhost') %>"
|
||||
database: "<%= ENV.fetch('POSTGRES_DATABASE', 'chatwoot_production') %>"
|
||||
username: "<%= ENV.fetch('POSTGRES_USERNAME_RR', 'chatwoot_prod_readonly') %>"
|
||||
password: "<%= ENV.fetch('POSTGRES_PASSWORD_RR', 'chatwoot_prod') %>"
|
||||
replica: true
|
||||
|
||||
Reference in New Issue
Block a user