To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 67 / 67033650beede216a5816e08cbac9739681ad082.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (495 Bytes)

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

    
12
  def self.down
13
    remove_column :enumerations, :position
14
  end
15
end