Class: AddRoleToUsers

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/templates/add_role_to_users.rb

Class Method Summary collapse

Class Method Details

.downObject



11
12
13
14
15
# File 'lib/generators/templates/add_role_to_users.rb', line 11

def self.down
  add_column :users, :admin, :boolean, :default => false
  Atreides::User.where(:role => :admin).each {|user| user.update_attributes!(:admin => true)}
  remove_column :users, :role
end

.upObject



2
3
4
5
6
7
8
9
# File 'lib/generators/templates/add_role_to_users.rb', line 2

def self.up
  add_column :users, :role, :string
  Atreides::User.where(:admin => true).each do |user|
    user.role = :admin
    user.save
  end
  remove_column :users, :admin
end