-require 'lib/migrate'
+require 'migrate'
class CreateUserRoles < ActiveRecord::Migration
def self.up
end
add_column :user_roles, :role, :user_role_enum, :null => false
- User.all(:conditions => ['administrator = ?', true]).each do |user|
+ User.where(:administrator => true).each do |user|
UserRole.create(:user_id => user.id, :role => "administrator")
end
remove_column :users, :administrator
add_foreign_key :user_roles, [:user_id], :users, [:id]
- add_index :user_roles, [:user_id]
end
def self.down
add_column :users, :administrator, :boolean, :default => false, :null => false
- UserRole.all(:conditions => ['role = ?', "administrator"]).each do |role|
+ UserRole.where(:role => "administrator").each do |role|
user = User.find(role.user_id)
user.administrator = true
user.save!