X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3e99bbf5a9e124a59fc5ae72c863e89af7fa8c46..98bfaace9aeba7fb387596cc16b2e661506173c6:/db/migrate/051_add_status_to_user.rb?ds=sidebyside diff --git a/db/migrate/051_add_status_to_user.rb b/db/migrate/051_add_status_to_user.rb index 01d501d01..f170e0de8 100644 --- a/db/migrate/051_add_status_to_user.rb +++ b/db/migrate/051_add_status_to_user.rb @@ -1,14 +1,15 @@ -require 'migrate' +class AddStatusToUser < ActiveRecord::Migration[4.2] + class User < ApplicationRecord + end -class AddStatusToUser < ActiveRecord::Migration def self.up - create_enumeration :user_status_enum, ["pending","active","confirmed","suspended","deleted"] + create_enumeration :user_status_enum, %w[pending active confirmed suspended deleted] add_column :users, :status, :user_status_enum, :null => false, :default => "pending" - User.update_all("status = 'deleted'", { :visible => false }) - User.update_all("status = 'pending'", { :visible => true, :active => 0 }) - User.update_all("status = 'active'", { :visible => true, :active => 1 }) + User.where(:visible => false).update_all(:status => "deleted") + User.where(:visible => true, :active => 0).update_all(:status => "pending") + User.where(:visible => true, :active => 1).update_all(:status => "active") remove_column :users, :active remove_column :users, :visible @@ -18,9 +19,9 @@ class AddStatusToUser < ActiveRecord::Migration add_column :users, :visible, :boolean, :default => true, :null => false add_column :users, :active, :integer, :default => 0, :null => false - User.update_all("visible = true, active = 1", { :status => "active" }) - User.update_all("visible = true, active = 0", { :status => "pending" }) - User.update_all("visible = false, active = 1", { :status => "deleted" }) + User.where(:status => "active").update_all(:visible => true, :active => 1) + User.where(:status => "pending").update_all(:visible => true, :active => 0) + User.where(:status => "deleted").update_all(:visible => false, :active => 1) remove_column :users, :status