Redmine/db/migrate/072_add_enumerations_position.rb
Jean-Philippe Lang c216ab325b Added position on Enumeration model.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@800 e93f8b46-1217-0410-a6f0-8f06a7374b81
2007-10-04 17:04:50 +00:00

13 lines
379 B
Ruby

class AddEnumerationsPosition < ActiveRecord::Migration
def self.up
add_column :enumerations, :position, :integer, :default => 1, :null => false
Enumeration.find(:all).group_by(&:opt).each_value do |enums|
enums.each_with_index {|enum, i| enum.update_attribute(:position, i+1)}
end
end
def self.down
remove_column :enumerations, :position
end
end