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 / 32 / 328e5d644f9c7f34ce3b37165d648bfc6611fce5.svn-base @ 1298:4f746d8966dd

History | View | Annotate | Download (448 Bytes)

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

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