You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: 20230421202218_fix_bad_user_roles.rb
    path of file: ./repos/human-essentials/db/migrate
    
    the code of the file until where you have to start completion: class FixBadUserRoles < ActiveRecord::Migration[7.0]
  def change
    bad_roles = Role.al
    
  def change
    bad_roles = Role.all.select { |r| r.resource_type && r.resource.nil? }

    bad_roles.each do |role|
      UsersRole.where(role_id: role.id).destroy_all
      role.destroy
    end
  end