diff --git a/app/models/simple_configuration.rb b/app/models/simple_configuration.rb index bbe8214..75bca93 100644 --- a/app/models/simple_configuration.rb +++ b/app/models/simple_configuration.rb @@ -1,50 +1,51 @@ class SimpleConfiguration < ActiveRecord::Base establish_connection ARCHIVING_CONF DAYS = { monday: :mon, tuesday: :tue, wednesday: :wed, thursday: :thu, friday: :fri, saturday: :sat, sunday: :sun } enum day: { monday: 0, tuesday: 1, wednesday: 2, thursday: 3, friday: 4, saturday: 5, sunday: 6 } belongs_to :host validates :host, :day, :hour, :minute, presence: true validates :hour, numericality: { greater_than_or_equal: 0, less_then: 24 } validates :minute, numericality: { greater_than_or_equal: 0, less_then: 60 } + validates_with NameValidator # Initializes the configuration's 3 parameters randomnly. # Default configurations must be randomized in order to distribute the backup server's # load. def randomize self.day = SimpleConfiguration.days.keys.sample self.hour = rand(24) self.minute = rand(60) end # The day abbreviation # # @return [Symbol] def day_short DAYS[day.to_sym] end # Creates a default config, by adding resources for: # # * schedule # * fileset # * job # # Each resource handles its own defaults. def create_config schedule = host.schedules.new.default_resource(day_short, hour, minute) fileset = host.filesets.new.default_resource job = host.job_templates.new(fileset_id: fileset.id, schedule_id: schedule.id).default_resource end end diff --git a/db/migrate/20161127123038_add_name_to_simple_configuration.rb b/db/migrate/20161127123038_add_name_to_simple_configuration.rb new file mode 100644 index 0000000..e267e02 --- /dev/null +++ b/db/migrate/20161127123038_add_name_to_simple_configuration.rb @@ -0,0 +1,5 @@ +class AddNameToSimpleConfiguration < ActiveRecord::Migration + def change + add_column :simple_configurations, :name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 648c7c4..2ba07f5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,150 +1,151 @@ # encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161126164445) do +ActiveRecord::Schema.define(version: 20161127123038) do create_table "configuration_settings", force: true do |t| t.string "job", default: "{}" t.string "client", default: "{}" t.datetime "created_at" t.datetime "updated_at" t.string "pool", default: "{}" end create_table "faqs", force: true do |t| t.string "title" t.text "body" t.integer "priority", default: 0 t.datetime "created_at" t.datetime "updated_at" end create_table "filesets", force: true do |t| t.string "name" t.integer "host_id" t.text "exclude_directions" t.text "include_directions" t.datetime "created_at" t.datetime "updated_at" end add_index "filesets", ["host_id"], name: "index_filesets_on_host_id", using: :btree create_table "hosts", force: true do |t| t.binary "name", limit: 255, null: false t.binary "fqdn", limit: 255, null: false t.integer "port", null: false t.integer "file_retention", null: false t.integer "job_retention", null: false t.datetime "created_at" t.datetime "updated_at" t.string "password" t.boolean "baculized", default: false, null: false t.datetime "baculized_at" t.integer "status", limit: 1, default: 0 t.integer "client_id" t.boolean "verified", default: false t.datetime "verified_at" t.integer "verifier_id" t.string "job_retention_period_type" t.string "file_retention_period_type" t.integer "origin", limit: 1 t.string "email_recipients", default: "[]" t.integer "quota", limit: 8, default: 104857600 end add_index "hosts", ["name"], name: "index_hosts_on_name", unique: true, length: {"name"=>128}, using: :btree create_table "invitations", force: true do |t| t.integer "user_id" t.integer "host_id" t.string "verification_code" t.datetime "created_at" t.datetime "updated_at" end add_index "invitations", ["user_id", "verification_code"], name: "index_invitations_on_user_id_and_verification_code", using: :btree create_table "job_templates", force: true do |t| t.string "name", null: false t.integer "job_type", limit: 1 t.integer "host_id" t.integer "fileset_id" t.integer "schedule_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "enabled", default: true t.binary "restore_location" t.boolean "baculized", default: false t.datetime "baculized_at" t.string "client_before_run_file" t.string "client_after_run_file" end create_table "ownerships", force: true do |t| t.integer "user_id" t.integer "host_id" t.datetime "created_at" t.datetime "updated_at" end create_table "schedule_runs", force: true do |t| t.integer "schedule_id" t.integer "level", limit: 1 t.string "month" t.string "day" t.string "time" t.datetime "created_at" t.datetime "updated_at" end add_index "schedule_runs", ["schedule_id"], name: "index_schedule_runs_on_schedule_id", using: :btree create_table "schedules", force: true do |t| t.string "name" t.string "runs" t.integer "host_id" end add_index "schedules", ["host_id"], name: "index_schedules_on_host_id", using: :btree create_table "simple_configurations", force: true do |t| t.integer "host_id" t.integer "day", limit: 1, null: false t.integer "hour", limit: 1, null: false t.integer "minute", limit: 1, null: false t.datetime "created_at" t.datetime "updated_at" + t.string "name" end create_table "users", force: true do |t| t.string "username", null: false t.string "email" t.integer "user_type", limit: 1, null: false t.boolean "enabled", default: false t.datetime "created_at" t.datetime "updated_at" t.string "identifier" t.string "password_hash" t.datetime "login_at" t.datetime "hosts_updated_at" t.string "temp_hosts", default: "[]" t.string "token" t.boolean "moderator", default: false end add_index "users", ["identifier"], name: "index_users_on_identifier", using: :btree add_index "users", ["password_hash"], name: "index_users_on_password_hash", using: :btree add_index "users", ["token"], name: "index_arch.users_on_token", using: :btree end