Refactor settings

This commit is contained in:
Martin Lensment 2014-10-15 17:49:42 +03:00
parent 26f5eda636
commit dafcb6f78c
25 changed files with 132 additions and 282 deletions

View file

@ -1,9 +0,0 @@
class CreateSettings < ActiveRecord::Migration
def change
create_table :settings do |t|
t.integer :setting_group_id
t.string :code
t.string :value
end
end
end

View file

@ -0,0 +1,18 @@
class CreateSettings < ActiveRecord::Migration
def self.up
drop_table :settings
create_table :settings do |t|
t.string :var, :null => false
t.text :value, :null => true
t.integer :thing_id, :null => true
t.string :thing_type, :limit => 30, :null => true
t.timestamps
end
add_index :settings, [ :thing_type, :thing_id, :var ], :unique => true
end
def self.down
drop_table :settings
end
end

View file

@ -0,0 +1,17 @@
class CorrectSettings < ActiveRecord::Migration
def up
drop_table :setting_groups
Setting.ds_algorithm = 2
Setting.ds_data_allowed = true
Setting.ds_data_with_key_allowed = true
Setting.key_data_allowed = true
Setting.dnskeys_min_count = 0
Setting.dnskeys_max_count = 9
Setting.ns_min_count = 2
Setting.ns_max_count = 11
Setting.transfer_wait_time = 0
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141014073435) do
ActiveRecord::Schema.define(version: 20141015135742) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -252,15 +252,16 @@ ActiveRecord::Schema.define(version: 20141014073435) do
t.datetime "updated_at"
end
create_table "setting_groups", force: true do |t|
t.string "code"
create_table "settings", force: true do |t|
t.string "var", null: false
t.text "value"
t.integer "thing_id"
t.string "thing_type", limit: 30
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "settings", force: true do |t|
t.integer "setting_group_id"
t.string "code"
t.string "value"
end
add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree
create_table "users", force: true do |t|
t.string "username"

View file

@ -66,27 +66,16 @@ User.where(
country: Country.where(name: 'Estonia').first
).first_or_create
sg = SettingGroup.where(code: 'domain_validation').first_or_create
Setting.destroy_all
s_1 = Setting.where(code: 'ns_min_count').first_or_create
s_1.value = 1
Setting.create(code: Setting::DS_ALGORITHM, value: 2)
Setting.create(code: Setting::ALLOW_DS_DATA, value: 1)
Setting.create(code: Setting::ALLOW_DS_DATA_WITH_KEY, value: 1)
Setting.create(code: Setting::ALLOW_KEY_DATA, value: 1)
s_2 = Setting.where(code: 'ns_max_count').first_or_create
s_2.value = 13
Setting.create(code: Setting::DNSKEYS_MIN_COUNT, value: 9)
Setting.create(code: Setting::DNSKEYS_MAX_COUNT, value: 0)
Setting.create(code: Setting::NS_MIN_COUNT, value: 2)
Setting.create(code: Setting::NS_MAX_COUNT, value: 11)
s_3 = Setting.where(code: 'dnskeys_min_count').first_or_create
s_3.value = 0
s_4 = Setting.where(code: 'dnskeys_max_count').first_or_create
s_4.value = 9
sg.settings = [s_1, s_2, s_3, s_4]
sg.save
sg = SettingGroup.where(code: 'domain_general').first_or_create
s_1 = Setting.where(code: 'transfer_wait_time').first_or_create
s_1.value = 0
sg.settings = [s_1]
sg.save
Setting.create(code: Setting::TRANSFER_WAIT_TIME, value: 0)