title: Store deleted records from database to a CSV
body: <p>There are nearly 1 million User records, so we are removing non-active users to maintain table consistency. We are using the Sinatra framework.</p>
  
  <p>In our model : </p>
  
  <pre><code>class UserInfo &lt; ActiveRecord::Base
    def delete_expired_users
      begin
        @expired_users = UserInfo.where("status != ? and UEndDate &lt; ?", "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
  </code></pre>