Skip to content

Commit

Permalink
Merge pull request #96 from DMPbelgium/clean_users
Browse files Browse the repository at this point in the history
Adds a rake task to delete all users created more than 1 year ago and who never had any activity
  • Loading branch information
StCyr authored May 23, 2024
2 parents 001375d + 8ce79f7 commit 0faf055
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 0faf055

Please sign in to comment.