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.

072_add_enumerations_position.rb 495B

123456789101112131415
  1. class AddEnumerationsPosition < ActiveRecord::Migration
  2. def self.up
  3. add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position')
  4. Enumeration.find(:all).group_by(&:opt).each do |opt, enums|
  5. enums.each_with_index do |enum, i|
  6. # do not call model callbacks
  7. Enumeration.update_all "position = #{i+1}", {:id => enum.id}
  8. end
  9. end
  10. end
  11. def self.down
  12. remove_column :enumerations, :position
  13. end
  14. end