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

Move schema aware defaults to build_from_defaults

This way we can reuse the safe setting
parent 1ae28e0e
......@@ -23,7 +23,12 @@ module CacheableAttributes
end
def build_from_defaults(attributes = {})
new(defaults.merge(attributes))
final_attributes = defaults
.merge(attributes)
.stringify_keys
.slice(*column_names)
new(final_attributes)
end
def cached
......
......@@ -47,14 +47,7 @@ module Gitlab
# defaults for missing columns.
if ActiveRecord::Migrator.needs_migration?
db_attributes = current_settings&.attributes || {}
column_names = ::ApplicationSetting.column_names
final_attributes = ::ApplicationSetting
.defaults
.merge(db_attributes)
.stringify_keys
.slice(*column_names)
::ApplicationSetting.new(final_attributes)
::ApplicationSetting.build_from_defaults(db_attributes)
elsif current_settings.present?
current_settings
else
......
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