Commit 1ae28e0e authored by Lin Jen-Shin's avatar Lin Jen-Shin Committed by Rémy Coutable

Return fake if and only if there's no database

Because `connect_to_db?` already detects if the table exists or not
parent 71672dfa
...@@ -7,10 +7,6 @@ module Gitlab ...@@ -7,10 +7,6 @@ module Gitlab
Gitlab::SafeRequestStore.fetch(:current_application_settings) { ensure_application_settings! } Gitlab::SafeRequestStore.fetch(:current_application_settings) { ensure_application_settings! }
end end
def fake_application_settings(attributes = {})
Gitlab::FakeApplicationSettings.new(::ApplicationSetting.defaults.merge(attributes || {}))
end
def clear_in_memory_application_settings! def clear_in_memory_application_settings!
@in_memory_application_settings = nil @in_memory_application_settings = nil
end end
...@@ -58,28 +54,21 @@ module Gitlab ...@@ -58,28 +54,21 @@ module Gitlab
.stringify_keys .stringify_keys
.slice(*column_names) .slice(*column_names)
return ::ApplicationSetting.new(final_attributes) ::ApplicationSetting.new(final_attributes)
end elsif current_settings.present?
current_settings
return current_settings if current_settings.present? else
::ApplicationSetting.create_from_defaults ||
with_fallback_to_fake_application_settings do in_memory_application_settings
::ApplicationSetting.create_from_defaults || in_memory_application_settings
end end
end end
def in_memory_application_settings def fake_application_settings(attributes = {})
with_fallback_to_fake_application_settings do Gitlab::FakeApplicationSettings.new(::ApplicationSetting.defaults.merge(attributes || {}))
@in_memory_application_settings ||= ::ApplicationSetting.build_from_defaults
end
end end
def with_fallback_to_fake_application_settings(&block) def in_memory_application_settings
yield @in_memory_application_settings ||= ::ApplicationSetting.build_from_defaults
rescue
# In case the application_settings table is not created yet, or if a new
# ApplicationSetting column is not yet migrated we fallback to a simple OpenStruct
fake_application_settings
end end
def connect_to_db? def connect_to_db?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment