mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
Allow nil values for settings
This commit is contained in:
parent
49f11cce0b
commit
e7eaba7963
3 changed files with 11 additions and 5 deletions
|
@ -1,6 +1,5 @@
|
|||
class SettingEntry < ApplicationRecord
|
||||
validates :code, presence: true, uniqueness: true
|
||||
validates :value, presence: true
|
||||
validates :format, presence: true
|
||||
validates :group, presence: true
|
||||
validate :valid_value_format
|
||||
|
@ -17,7 +16,7 @@ class SettingEntry < ApplicationRecord
|
|||
|
||||
def retrieve
|
||||
method = VALUE_FORMATS[format]
|
||||
send(method)
|
||||
value.blank? ? nil : send(method)
|
||||
end
|
||||
|
||||
def self.with_group(group_name)
|
||||
|
@ -32,7 +31,8 @@ class SettingEntry < ApplicationRecord
|
|||
stg_value = args[0].to_s
|
||||
SettingEntry.find_by!(code: stg_code).update(value: stg_value)
|
||||
else
|
||||
SettingEntry.find_by!(code: method.to_s).retrieve
|
||||
stg = SettingEntry.find_by(code: method.to_s)
|
||||
stg ? stg.retrieve : nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeSettingEntryValueToAllowNil < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_column :setting_entries, :value, :string, null: true
|
||||
end
|
||||
end
|
|
@ -2269,7 +2269,7 @@ CREATE TABLE public.schema_migrations (
|
|||
CREATE TABLE public.setting_entries (
|
||||
id bigint NOT NULL,
|
||||
code character varying NOT NULL,
|
||||
value character varying DEFAULT ''::character varying NOT NULL,
|
||||
value character varying DEFAULT ''::character varying,
|
||||
"group" character varying NOT NULL,
|
||||
format character varying NOT NULL,
|
||||
creator_str character varying,
|
||||
|
@ -4779,6 +4779,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20200630081231'),
|
||||
('20200714115338'),
|
||||
('20200807110611'),
|
||||
('20200811074839');
|
||||
('20200811074839'),
|
||||
('20200812090409');
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue