Source code for the custom Mastodon (Glitchsoc) instance on berserker.town. https://berserker.town/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
919 B

# frozen_string_literal: true
class MigrateRoles < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
class UserRole < ApplicationRecord; end
class User < ApplicationRecord; end
def up
load Rails.root.join('db', 'seeds', '03_roles.rb')
owner_role = UserRole.find_by(name: 'Owner')
moderator_role = UserRole.find_by(name: 'Moderator')
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, 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