You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

078_add_custom_fields_position.rb 452B

123456789101112131415
  1. class AddCustomFieldsPosition < ActiveRecord::Migration[4.2]
  2. def self.up
  3. add_column(:custom_fields, :position, :integer, :default => 1)
  4. CustomField.all.group_by(&:type).each do |t, fields|
  5. fields.each_with_index do |field, i|
  6. # do not call model callbacks
  7. CustomField.where({:id => field.id}).update_all(:position => (i+1))
  8. end
  9. end
  10. end
  11. def self.down
  12. remove_column :custom_fields, :position
  13. end
  14. end