3 class AddStatusToUser < ActiveRecord::Migration
5 create_enumeration :user_status_enum, ["pending","active","confirmed","suspended","deleted"]
7 add_column :users, :status, :user_status_enum, :null => false, :default => "pending"
9 User.update_all("status = 'deleted'", { :visible => false })
10 User.update_all("status = 'pending'", { :visible => true, :active => 0 })
11 User.update_all("status = 'active'", { :visible => true, :active => 1 })
13 remove_column :users, :active
14 remove_column :users, :visible
18 add_column :users, :visible, :boolean, :default => true, :null => false
19 add_column :users, :active, :integer, :default => 0, :null => false
21 User.update_all("visible = true, active = 1", { :status => "active" })
22 User.update_all("visible = true, active = 0", { :status => "pending" })
23 User.update_all("visible = false, active = 1", { :status => "deleted" })
25 remove_column :users, :status
27 drop_enumeration :user_status_enum