-
Notifications
You must be signed in to change notification settings - Fork 33
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
Update sample_public_name for RVI Program - Bait Capture study #4586
Changes from 3 commits
d2a1e63
b99815b
6abc012
dc4d9e2
0e5e9c4
a8b9d8b
44fb065
bd34e04
732b395
d26dfce
95a65bb
70c8ee3
3d45f75
b37bb16
1035686
a989cd1
190186e
1ee65bb
e2a9a3c
7899d2f
1e86205
7238682
350bf8d
2875b4b
eae764b
ad678b0
8db61fe
bcf93b1
5855031
edecf37
ee72d10
721fb23
4262bc5
83a70ae
6f565df
899fa6f
9549c99
4f2c7b7
6f91035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
namespace :samples do | ||
desc 'Update sample_public_name for RVI Program - Bait Capture study' | ||
task update_public_name: :environment do | ||
ActiveRecord::Base.connection.execute('SET autocommit = 0') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain the benefit of having autocommit turned off, please? I was reading the docs - https://dev.mysql.com/doc/refman/8.4/en/innodb-autocommit-commit-rollback.html - and it looks like the benefit would come if there were multiple SQL statements - but we only have one here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right; it is only one SQL statement, but it runs on all the samples of the RVI studies (quite a lot). Turning off auto-commit ensures the atomicity of the operation. |
||
|
||
ActiveRecord::Base.connection.execute(<<~SQLQUERY) | ||
UPDATE sample_metadata | ||
JOIN samples ON sample_metadata.sample_id = samples.id | ||
JOIN study_samples ON sample_metadata.sample_id = study_samples.sample_id | ||
JOIN studies ON study_samples.study_id = studies.id | ||
SET sample_metadata.sample_public_name = samples.sanger_sample_id | ||
WHERE studies.name = 'RVI Program - Bait Capture' AND sanger_sample_id LIKE 'RVI%'; | ||
SQLQUERY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you consider whether to check if |
||
|
||
ActiveRecord::Base.connection.execute('COMMIT') | ||
ActiveRecord::Base.connection.execute('SET autocommit = 1') | ||
|
||
puts 'Sample public names updated successfully for RVI Program - Bait Capture study.' | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using SQL directly means not using the ORM... which I think might mean you're bypassing some useful functionality. When a sample (and hopefully sample metadata) is updated, Sequencescape automatically updates the corresponding value in the MLWH (via the RabbitMQ queue). If you directly use SQL, I don't think this will happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!