020_add_role_position.rb 287 Bytes
Newer Older
1 2
class AddRolePosition < ActiveRecord::Migration
  def self.up
3
    add_column :roles, :position, :integer, :default => 1
4
    Role.update_all("position = (SELECT COUNT(*) FROM #{Role.table_name} r WHERE r.id < id) + 1")
5 6 7 8 9 10
  end

  def self.down
    remove_column :roles, :position
  end
end