Our table contains nearly 1 million records, so we are removing non-active users from User table to maintain table consistency. Mainly we want to store all the deleted records in a csv file.
we are using Ruby, sinatra framework.
Here is the code :
In our model :
class UserInfo < ActiveRecord::Base def delete_expired_users begin @expired_users = UserInfo.where("status != ? and UEndDate < ?", "active", 3.months.ago ) @expired_users.find_each do |user| # as we have 500k records to delete, used "find_each" IS THIS ASYNCHRONOUS WAY TO DELETE? user.destroy # I NEED TO STORE THIS DESTROYED USER IN A CSV FILE. end rescue raise end end end
How to export deleted records to csv?