$ heroku run console --app MY_APP --no-tty < import_remote_csv.rb
Last active
June 26, 2020 01:18
-
-
Save thadeu/e34a06a1f7f29ad8e5d404c990ee204a to your computer and use it in GitHub Desktop.
Import CSV to heroku from remote csv
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
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