Skip to content

Commit

Permalink
Rake task to update new fields for existing batches (#1958)
Browse files Browse the repository at this point in the history
* Rake task to update new fields for existing batches

* Delete public file with the new fields to upload it manually
  • Loading branch information
leandroradusky authored Jul 7, 2023
1 parent d70369d commit 71a240b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/tasks/batches_labels.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'csv'

namespace :batches_labels do
desc "Update batches label fields"
task :import, [:csv_file] => :environment do |task, args|
path = args[:csv_file] || abort("Usage: $> rake batches_labels:import[path/to/file.csv] RAILS_ENV={env}")

CSV.foreach(path, headers: true) do |row|
batch = Batch.find_by(batch_number: row['batch_number'])
if batch
batch.reference_gene = row['reference_gene']
batch.target_organism_taxonomy_id = row['target_organism_taxonomy_id']
batch.pango_lineage = row['pango_lineage']
batch.who_label = row['who_label']
batch.save
end
end
end
end

0 comments on commit 71a240b

Please sign in to comment.