Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rake task to update new fields for existing batches #1958

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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