Last active
August 7, 2017 21:37
-
-
Save agustinf/4a930790d5f5e137061a4354294fdb2d to your computer and use it in GitHub Desktop.
delete_people_using_csv.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
include PersonCsvHelper | |
class DeletePeopleUsingCsv < PowerTypes::Command.new(:file_path) | |
def perform | |
for_each_row do |row| | |
Rails.logger.info("doing the thing") | |
next unless row[:email] | |
person = Person.find_by(email: row[:email]) | |
if person | |
Rails.logger.error("theres a person #{person.email}") | |
begin | |
person.destroy | |
rescue ActiveRecord::InvalidForeignKey | |
Rails.logger.error("Could not delete '#{person.email}'.") | |
end | |
else | |
Rails.logger.info("Tried to delete non existing person. Ignoring.") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment