From 0388a15c15614527a43309a921585db754a25cd9 Mon Sep 17 00:00:00 2001 From: "depfu[bot]" <23717796+depfu[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:15:51 +0000 Subject: [PATCH 1/6] Update rubocop-performance to version 1.22.1 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1fa98ff..c72f873 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,7 +160,7 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.32.3) parser (>= 3.3.1.0) - rubocop-performance (1.21.1) + rubocop-performance (1.22.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-rails (2.25.1) From 067bec2a50cbfd939e472c4574164b6a0ec0a1db Mon Sep 17 00:00:00 2001 From: "depfu[bot]" <23717796+depfu[bot]@users.noreply.github.com> Date: Sun, 22 Sep 2024 05:50:28 +0000 Subject: [PATCH 2/6] Update rubocop-rails to version 2.26.2 --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6f44c72..ce1fc95 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,7 +71,7 @@ GEM guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) hashie (5.0.0) - i18n (1.14.5) + i18n (1.14.6) concurrent-ruby (~> 1.0) json (2.7.2) language_server-protocol (3.17.0.3) @@ -163,7 +163,7 @@ GEM rubocop-performance (1.21.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.26.1) + rubocop-rails (2.26.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.52.0, < 2.0) From 7875ee368217403e87e50924e3a20110642480a1 Mon Sep 17 00:00:00 2001 From: Seena Nair <55585488+seenanair@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:36:49 +0100 Subject: [PATCH 3/6] feat: Add rake task to update id_sample_lims column to sample name in samples table --- lib/tasks/update_id_sample_lims.rake | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/tasks/update_id_sample_lims.rake diff --git a/lib/tasks/update_id_sample_lims.rake b/lib/tasks/update_id_sample_lims.rake new file mode 100644 index 0000000..14fead5 --- /dev/null +++ b/lib/tasks/update_id_sample_lims.rake @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +# Rails task to update the id_sample_lims column based on the name column in samples table for samples +# Why is this task needed? +# The id_sample_lims column in the samples table is used to store the ID of the sample in Traction. +# However, this is clashing with IDs in the sample table in the warehouse, causing problems for NPG. +# NPG relies on the uniqueness of these IDs as they use Sequencescape IDs. +# To resolve this issue, we need to update the id_sample_lims column to the value of the name column for samples where id_lims is "Traction". +namespace :sample_table do + # This rake task updates the id_sample_lims column to the value of the name column + # for samples where id_lims is "Traction". If the name is already present in the + # id_sample_lims column, the sample will be skipped. + # + # Usage: bundle exec rake sample_table:update_id_sample_lims + # + # The task performs the following steps: + # 1. Fetch all samples where id_lims is "Traction". + # 2. For each sample, check if the name is already present in the id_sample_lims column. + # 3. If the name is not present, update the id_sample_lims column to the value of the name column. + # 4. Skip the sample if the name is already present in the id_sample_lims column. + # + desc 'Update id_sample_lims column to the value of the name column if id_lims is "Traction"' + + task update_id_sample_lims: :environment do + Sample.where(id_lims: 'Traction').find_each do |sample| + # Skip updating the sample if the id_sample_lims already contains the sample's name + next if Sample.exists?(id_sample_lims: sample.name) + + puts "Updating id_sample_lims for sample #{sample.id} to #{sample.name}" + sample.id_sample_lims = sample.name + + begin + sample.save! + rescue ActiveRecord::ActiveRecordError, StandardError => e + puts "Failed to update id_sample_lims for sample #{sample.id}: #{e.message}" + end + end + end +end From 0a64b847461dd35504cf06d46a727d99c778accf Mon Sep 17 00:00:00 2001 From: Seena Nair <55585488+seenanair@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:38:39 +0100 Subject: [PATCH 4/6] test: add RSpec tests for sample_table:update_id_sample_lims rake task --- .../tasks/update_id_sample_lims.rake_spec.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/lib/tasks/update_id_sample_lims.rake_spec.rb diff --git a/spec/lib/tasks/update_id_sample_lims.rake_spec.rb b/spec/lib/tasks/update_id_sample_lims.rake_spec.rb new file mode 100644 index 0000000..f0bd43c --- /dev/null +++ b/spec/lib/tasks/update_id_sample_lims.rake_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rake' +# only load Rake tasks if they haven't been loaded already +Rails.application.load_tasks if Rake::Task.tasks.empty? + +RSpec.describe 'RakeTasks' do + describe 'sample_table:update_id_sample_lims' do + let!(:traction_sample) { create(:sample, id_lims: 'Traction', name: 'SampleName1', id_sample_lims: 'OldValue1', uuid_sample_lims: SecureRandom.uuid) } + let!(:non_traction_sample) { create(:sample, id_lims: 'Other', name: 'SampleName2', id_sample_lims: 'OldValue2', uuid_sample_lims: SecureRandom.uuid) } + let!(:existing_sample) { create(:sample, id_lims: 'Traction', name: 'SampleName1', id_sample_lims: 'OldValue2', uuid_sample_lims: SecureRandom.uuid) } + + it 'updates id_sample_lims to the value of the name column for traction samples' do + expect { Rake::Task['sample_table:update_id_sample_lims'].invoke }.to change { traction_sample.reload.id_sample_lims }.from('OldValue1').to('SampleName1').and output( + /Updating id_sample_lims for sample #{traction_sample.id} to SampleName1/ + ).to_stdout + end + + it 'does not change id_sample_lims for non-traction samples' do + expect { Rake::Task['sample_table:update_id_sample_lims'].invoke }.not_to(change { non_traction_sample.reload.id_sample_lims }) + end + + it 'does not change id_sample_lims if the name is already in id_sample_lims' do + expect { Rake::Task['sample_table:update_id_sample_lims'].invoke }.not_to(change { existing_sample.reload.id_sample_lims }) + end + it 'raises an error if saving the sample fails' do + allow_any_instance_of(Sample).to receive(:save!).and_raise(ActiveRecord::ActiveRecordError, 'Simulated save error') + + expect do + Rake::Task['sample_table:update_id_sample_lims'].invoke + end.to output(/Failed to update id_sample_lims for sample #{traction_sample.id}: Simulated save error/).to_stdout + end + end +end From ad596ec7927b0320dd137c1f6dcdf8dcae175aa3 Mon Sep 17 00:00:00 2001 From: Seena Nair <55585488+seenanair@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:55:26 +0100 Subject: [PATCH 5/6] tests: added reenable to ensure the task is reloaded before each invocation --- spec/lib/tasks/update_id_sample_lims.rake_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/lib/tasks/update_id_sample_lims.rake_spec.rb b/spec/lib/tasks/update_id_sample_lims.rake_spec.rb index f0bd43c..5ff3472 100644 --- a/spec/lib/tasks/update_id_sample_lims.rake_spec.rb +++ b/spec/lib/tasks/update_id_sample_lims.rake_spec.rb @@ -11,6 +11,10 @@ let!(:non_traction_sample) { create(:sample, id_lims: 'Other', name: 'SampleName2', id_sample_lims: 'OldValue2', uuid_sample_lims: SecureRandom.uuid) } let!(:existing_sample) { create(:sample, id_lims: 'Traction', name: 'SampleName1', id_sample_lims: 'OldValue2', uuid_sample_lims: SecureRandom.uuid) } + before do + Rake::Task['sample_table:update_id_sample_lims'].reenable + end + it 'updates id_sample_lims to the value of the name column for traction samples' do expect { Rake::Task['sample_table:update_id_sample_lims'].invoke }.to change { traction_sample.reload.id_sample_lims }.from('OldValue1').to('SampleName1').and output( /Updating id_sample_lims for sample #{traction_sample.id} to SampleName1/ From 2e18c6a4f6640f084a279547bfe13e0006478de0 Mon Sep 17 00:00:00 2001 From: Stephen Inglis <519327+stevieing@users.noreply.github.com> Date: Tue, 8 Oct 2024 08:47:35 +0100 Subject: [PATCH 6/6] Update .release-version --- .release-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.release-version b/.release-version index 3500250..57807d6 100644 --- a/.release-version +++ b/.release-version @@ -1 +1 @@ -1.21.0 +1.22.0