Created
April 3, 2022 14:52
-
-
Save jackyvo/ed5fb5a2ac88cfd2cce46558214ec5dc to your computer and use it in GitHub Desktop.
User destroy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################################################### | |
failed_list = [] | |
user_ids_with_enrollment = Enrollment.pluck(:user_id) | |
users_without_enrollment = User.where.not(id: user_ids_with_enrollment) | |
users_without_enrollment.find_each do |user| | |
failed_list << user.id unless user.destroy | |
end | |
p "Total users to delete: #{user_without_enrollment.length}" | |
p "Total users that not deleted: #{failed_list.length}" | |
######################################### | |
# Debug failed reason from list of failed | |
failed_list.each do |user_id| | |
begin | |
user = User.find_by(id: user_id) | |
user.destroy! | |
rescue Exception => ex | |
p "#{user_id}: => #{ex.message}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment