Skip to content

Instantly share code, notes, and snippets.

@agustinf
Last active August 7, 2017 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agustinf/4a930790d5f5e137061a4354294fdb2d to your computer and use it in GitHub Desktop.
Save agustinf/4a930790d5f5e137061a4354294fdb2d to your computer and use it in GitHub Desktop.
delete_people_using_csv.rb
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