mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
Source DB config more cleanly, fixes issues with socket in prd
This commit is contained in:
parent
fd95dbe75a
commit
abe814412e
|
@ -16,6 +16,19 @@ class GlobalSetting
|
|||
end
|
||||
end
|
||||
|
||||
def self.database_config
|
||||
hash = {"adapter" => "postgresql"}
|
||||
%w{pool timeout socket host port username password}.each do |s|
|
||||
if val = self.send("db_#{s}")
|
||||
hash[s] = val
|
||||
end
|
||||
end
|
||||
hash["host_names"] = [ hostname ]
|
||||
hash["database"] = db_name
|
||||
|
||||
{"production" => hash}
|
||||
end
|
||||
|
||||
|
||||
class BaseProvider
|
||||
def self.coerce(setting)
|
||||
|
|
|
@ -8,10 +8,21 @@ require_relative '../lib/discourse_plugin_registry'
|
|||
require_relative '../app/models/global_setting'
|
||||
|
||||
if defined?(Bundler)
|
||||
# If you precompile assets before deploying to production, use this line
|
||||
Bundler.require(*Rails.groups(assets: %w(development test profile)))
|
||||
# If you want your assets lazily compiled in production, use this line
|
||||
# Bundler.require(:default, :assets, Rails.env)
|
||||
end
|
||||
|
||||
# PATCH DB configuration
|
||||
class Rails::Application::Configuration
|
||||
|
||||
def database_configuration_with_global_config
|
||||
if Rails.env == "production"
|
||||
GlobalSetting.database_config
|
||||
else
|
||||
database_configuration_without_global_config
|
||||
end
|
||||
end
|
||||
|
||||
alias_method_chain :database_configuration, :global_config
|
||||
end
|
||||
|
||||
module Discourse
|
||||
|
|
|
@ -33,15 +33,8 @@ profile:
|
|||
host_names:
|
||||
- "localhost"
|
||||
|
||||
production:
|
||||
pool: <%= GlobalSetting.db_pool %>
|
||||
timeout: <%= GlobalSetting.db_timeout %>
|
||||
adapter: postgresql
|
||||
socket: <%= GlobalSetting.db_socket %>
|
||||
host: <%= GlobalSetting.db_host %>
|
||||
port: <%= GlobalSetting.db_port %>
|
||||
database: <%= GlobalSetting.db_name %>
|
||||
username: <%= GlobalSetting.db_username %>
|
||||
password: <%= GlobalSetting.db_password %>
|
||||
host_names:
|
||||
- <%= GlobalSetting.hostname %>
|
||||
# You may be surprised production is not here, it is sourced from application.rb using a monkey patch
|
||||
# This is done for 2 reasons
|
||||
#
|
||||
# 1. we need to support blank settings correctly and rendering nothing in yaml/erb is a PITA
|
||||
# 2. why go from object -> yaml -> object, pointless
|
||||
|
|
Loading…
Reference in New Issue
Block a user