2007-10-04 19:04:50 +02:00
|
|
|
class AddEnumerationsPosition < ActiveRecord::Migration
|
|
|
|
def self.up
|
2007-10-22 23:07:13 +02:00
|
|
|
add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position')
|
2012-12-02 21:28:37 +01:00
|
|
|
Enumeration.all.group_by(&:opt).each do |opt, enums|
|
2007-10-06 00:53:26 +02:00
|
|
|
enums.each_with_index do |enum, i|
|
|
|
|
# do not call model callbacks
|
2016-11-28 07:21:11 +01:00
|
|
|
Enumeration.where({:id => enum.id}).update_all(:position => (i+1))
|
2007-10-06 00:53:26 +02:00
|
|
|
end
|
2007-10-04 19:04:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
remove_column :enumerations, :position
|
|
|
|
end
|
|
|
|
end
|