Skip to content

Instantly share code, notes, and snippets.

@thadeu
Last active June 26, 2020 01:18
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 thadeu/e34a06a1f7f29ad8e5d404c990ee204a to your computer and use it in GitHub Desktop.
Save thadeu/e34a06a1f7f29ad8e5d404c990ee204a to your computer and use it in GitHub Desktop.
Import CSV to heroku from remote csv

Into terminal

$ heroku run console --app MY_APP --no-tty < import_remote_csv.rb
file_contents = open('some-public-url').read
csv = CSV.parse(file_contents, col_sep: ',') # set your col_sep
# in batch the 1_000
csv.each_slice(1_000) do |numbers_batch|
numbers_batch.map do |row|
id = row[0]
logo_id = row[1]
begin
user = User.with_deleted.find(id)
user.update_attribute(:logo_id, logo_id)
puts "user #{id}, logo_id #{user.logo_id}"
rescue
# puts "User notfound #{id} logo_id #{logo_id}"
# exception avoid
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment