diff options
Diffstat (limited to 'db/migrate/072_add_enumerations_position.rb')
-rw-r--r-- | db/migrate/072_add_enumerations_position.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/db/migrate/072_add_enumerations_position.rb b/db/migrate/072_add_enumerations_position.rb new file mode 100644 index 000000000..7def86772 --- /dev/null +++ b/db/migrate/072_add_enumerations_position.rb @@ -0,0 +1,12 @@ +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 |