Skip to content

Commit

Permalink
Change migration to migrate admins to Owner role rather than Admin ro…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Nov 2, 2022
1 parent 0f5e6dd commit cb27d89
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions db/post_migrate/20220617202502_migrate_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ class User < ApplicationRecord; end
def up
load Rails.root.join('db', 'seeds', '03_roles.rb')

admin_role = UserRole.find_by(name: 'Admin')
owner_role = UserRole.find_by(name: 'Owner')
moderator_role = UserRole.find_by(name: 'Moderator')

User.where(admin: true).in_batches.update_all(role_id: admin_role.id)
User.where(admin: true).in_batches.update_all(role_id: owner_role.id)
User.where(moderator: true).in_batches.update_all(role_id: moderator_role.id)
end

def down
admin_role = UserRole.find_by(name: 'Admin')
owner_role = UserRole.find_by(name: 'Owner')
moderator_role = UserRole.find_by(name: 'Moderator')

User.where(role_id: admin_role.id).in_batches.update_all(admin: true) if admin_role
User.where(role_id: [admin_role.id, owner_role.id]).in_batches.update_all(admin: true) if admin_role
User.where(role_id: moderator_role.id).in_batches.update_all(moderator: true) if moderator_role
end
end

0 comments on commit cb27d89

Please sign in to comment.