3 class CreateUserRoles < ActiveRecord::Migration
5 create_enumeration :user_role_enum, %w(administrator moderator)
7 create_table :user_roles do |t|
8 t.column :user_id, :bigint, :null => false
9 t.column :role, :user_role_enum, :null => false
11 t.timestamps :null => true
14 User.where(:administrator => true).each do |user|
15 UserRole.create(:user_id => user.id, :role => "administrator")
18 remove_column :users, :administrator
20 add_foreign_key :user_roles, :users, :name => "user_roles_user_id_fkey"
24 add_column :users, :administrator, :boolean, :default => false, :null => false
26 UserRole.where(:role => "administrator").each do |role|
27 user = User.find(role.user_id)
28 user.administrator = true
32 drop_table :user_roles
33 drop_enumeration :user_role_enum