I'm trying to create a rake file which will be linked to crontab, and will have the ability to lock users which are inactive for 90 days in the group ID 600, but something is not correct in the file. this is the lock_inactive_users.rake
namespace :redmine do
desc "Lock inactive users"
task lock_inactive_users: :environment do
inactive_users = User.joins(:groups)
.where('groups.id = ?', 600)
.where(type: 'User')
.where('last_login_on < ?', 90.days.ago)
inactive_users.find_each(batch_size: 500) do |user|
user.update(status: User::STATUS_LOCKED)
puts "User #{user.login} (ID: #{user.id}) has been locked."
end
end
end
while executing the file Im ending with error bundle exec rake redmine:lock_inactive_users RAILS_ENV=production
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "groups"
Any guidance will be much appreciated