FEATURE: allow setting postgres connection variables via environment

FEATURE: allow setting postgres connection variables via environment

diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb
index 8543ca6..fba25ec 100644
--- a/app/models/global_setting.rb
+++ b/app/models/global_setting.rb
@@ -154,6 +154,14 @@ class GlobalSetting
     hash["reaping_frequency"] = connection_reaper_interval if connection_reaper_interval.present?
     hash["advisory_locks"] = !!self.db_advisory_locks
 
+    db_variables = provider.keys.filter { |k| k.to_s.starts_with? 'db_variables_' }
+    if db_variables.length > 0
+      hash["variables"] = {}
+      db_variables.each do |k|
+        hash["variables"][k.slice(('db_variables_'.length)..)] = self.public_send(k)
+      end
+    end
+
     { "production" => hash }
   end
 
diff --git a/config/database.yml b/config/database.yml
index 32be426..be92da4 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -13,6 +13,9 @@ development:
     ###   - restart sidekiq if you change this setting
     ###   - rebake all to posts using: `RAILS_ENV=production bundle exec rake posts:rebake`
     - "localhost"
+  variables: <%= ENV.filter { |k,v| k.start_with? 'DISCOURSE_DB_VARIABLES_' }
+                    .transform_keys { |k| k.slice(('DISCOURSE_DB_VARIABLES_'.length)..).downcase }
+                    .to_json %>
 
 # Warning: The database defined as "test" will be erased and
 # re-generated from your development database when you run "rake".

GitHub sha: dda1cd6a

1 Like

This commit appears in #12699 which was approved by eviltrout. It was merged by Supermathie.