Skip to content

Commit

Permalink
Adds a rake task to delete all users created more than 1 year ago and
Browse files Browse the repository at this point in the history
who never had any activity

Signed-off-by: Cyrille Bollu <cyrille@belnet.be>
  • Loading branch information
Cyrille Bollu committed Apr 23, 2024
1 parent 9f484bf commit 8ce79f7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/tasks/belnet.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace :belnet do

namespace :users do

desc "Deletes users who never had any activity, after some time"
task :clean => :environment do

User.where(last_sign_in_at:nil).find_each do |user|

# Only consider users that have been created more than 1 year ago
if user.created_at.year < ( Date.today.year - 1 )

# Unlink user from any existing plan
role = Role.where(user_id:user.id).destroy_all

# Deletes user
user.destroy

end

end

end

end

end

0 comments on commit 8ce79f7

Please sign in to comment.