rake task to write displaynames coming from a csv file to the database
This commit is contained in:
17
lib/tasks/write_displaynames.rake
Normal file
17
lib/tasks/write_displaynames.rake
Normal file
@ -0,0 +1,17 @@
|
||||
namespace :user do
|
||||
require 'csv'
|
||||
|
||||
desc 'write displaynames retrieved from the account service as csv into the codeocean database'
|
||||
|
||||
task :write_displaynames, [:file_path_read] => [ :environment ] do |t, args|
|
||||
|
||||
csv_input = CSV.read(args[:file_path_read], headers:true)
|
||||
|
||||
csv_input.each do |row|
|
||||
user = ExternalUser.find_by(:external_id => row[0])
|
||||
puts "Change name from #{user.name} to #{row[1]}"
|
||||
user.update(name: row[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user