3 class CreateUserRoles < ActiveRecord::Migration
5 create_enumeration :user_role_enum, ["administrator", "moderator"]
7 create_table :user_roles do |t|
8 t.column :user_id, :bigint, :null => false
12 add_column :user_roles, :role, :user_role_enum, :null => false
14 User.where(:administrator => true).each do |user|
15 UserRole.create(:user_id => user.id, :role => "administrator")
17 remove_column :users, :administrator
19 add_foreign_key :user_roles, [:user_id], :users, [:id]
23 add_column :users, :administrator, :boolean, :default => false, :null => false
24 UserRole.where(:role => "administrator").each do |role|
25 user = User.find(role.user_id)
26 user.administrator = true
29 drop_table :user_roles
30 drop_enumeration :user_role_enum