3 class AddStatusToUser < ActiveRecord::Migration[4.2]
4 class User < ApplicationRecord
8 create_enumeration :user_status_enum, %w[pending active confirmed suspended deleted]
10 add_column :users, :status, :user_status_enum, :null => false, :default => "pending"
12 User.where(:visible => false).update_all(:status => "deleted")
13 User.where(:visible => true, :active => 0).update_all(:status => "pending")
14 User.where(:visible => true, :active => 1).update_all(:status => "active")
16 remove_column :users, :active
17 remove_column :users, :visible
21 add_column :users, :visible, :boolean, :default => true, :null => false
22 add_column :users, :active, :integer, :default => 0, :null => false
24 User.where(:status => "active").update_all(:visible => true, :active => 1)
25 User.where(:status => "pending").update_all(:visible => true, :active => 0)
26 User.where(:status => "deleted").update_all(:visible => false, :active => 1)
28 remove_column :users, :status
30 drop_enumeration :user_status_enum