mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-29 15:35:23 -04:00
Source DB config more cleanly, fixes issues with socket in prd
This commit is contained in:
parent
fd95dbe75a
commit
abe814412e
3 changed files with 32 additions and 15 deletions
|
@ -16,6 +16,19 @@ class GlobalSetting
|
||||||
end
|
end
|
||||||
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
|
class BaseProvider
|
||||||
def self.coerce(setting)
|
def self.coerce(setting)
|
||||||
|
|
|
@ -8,10 +8,21 @@ require_relative '../lib/discourse_plugin_registry'
|
||||||
require_relative '../app/models/global_setting'
|
require_relative '../app/models/global_setting'
|
||||||
|
|
||||||
if defined?(Bundler)
|
if defined?(Bundler)
|
||||||
# If you precompile assets before deploying to production, use this line
|
|
||||||
Bundler.require(*Rails.groups(assets: %w(development test profile)))
|
Bundler.require(*Rails.groups(assets: %w(development test profile)))
|
||||||
# If you want your assets lazily compiled in production, use this line
|
end
|
||||||
# Bundler.require(:default, :assets, Rails.env)
|
|
||||||
|
# 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
|
end
|
||||||
|
|
||||||
module Discourse
|
module Discourse
|
||||||
|
|
|
@ -33,15 +33,8 @@ profile:
|
||||||
host_names:
|
host_names:
|
||||||
- "localhost"
|
- "localhost"
|
||||||
|
|
||||||
production:
|
# You may be surprised production is not here, it is sourced from application.rb using a monkey patch
|
||||||
pool: <%= GlobalSetting.db_pool %>
|
# This is done for 2 reasons
|
||||||
timeout: <%= GlobalSetting.db_timeout %>
|
#
|
||||||
adapter: postgresql
|
# 1. we need to support blank settings correctly and rendering nothing in yaml/erb is a PITA
|
||||||
socket: <%= GlobalSetting.db_socket %>
|
# 2. why go from object -> yaml -> object, pointless
|
||||||
host: <%= GlobalSetting.db_host %>
|
|
||||||
port: <%= GlobalSetting.db_port %>
|
|
||||||
database: <%= GlobalSetting.db_name %>
|
|
||||||
username: <%= GlobalSetting.db_username %>
|
|
||||||
password: <%= GlobalSetting.db_password %>
|
|
||||||
host_names:
|
|
||||||
- <%= GlobalSetting.hostname %>
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue