Newer
Older
dmpopidor / db / migrate / 20170301105806_add_type_column_to_question_format.rb
@ray.carrick ray.carrick on 1 Mar 2017 791 bytes Optimistic Locking
class AddTypeColumnToQuestionFormat < ActiveRecord::Migration
  def self.up
    add_column  :question_formats, :formattype, :integer, :default => 0
    QuestionFormat.all.each do |qf|
      if qf.title == "Text area"
        qf.textarea = true
      end
      if qf.title == "Text field"
        qf.textfield = true
      end
      if qf.title == "Radio buttons"
        qf.radiobuttons = true
      end
      if qf.title == "Check box"
        qf.checkbox = true
      end
      if qf.title == "Dropdown"
        qf.dropdown = true
      end
      if qf.title == "Multi select box"
        qf.multiselectbox = true
      end
      if qf.title == "Date"
        qf.date = true
      end
      qf.save
    end
  end

  def self.down
    remove_column :question_formats, :formattype
  end
end