Mercurial > hg > soundsoftware-site
view db/migrate/072_add_enumerations_position.rb @ 1521:2354ddf5a483 redmine-2.5-integration
Fix some merge/runtime problems
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Tue, 09 Sep 2014 14:27:58 +0100 |
parents | 261b3d9a4903 |
children |
line wrap: on
line source
class AddEnumerationsPosition < ActiveRecord::Migration def self.up add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position') Enumeration.all.group_by(&:opt).each do |opt, enums| enums.each_with_index do |enum, i| # do not call model callbacks Enumeration.update_all "position = #{i+1}", {:id => enum.id} end end end def self.down remove_column :enumerations, :position end end