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