Skip to content

Commit 74c8ee0

Browse files
Convert to rake task
- This means that the normalisation can be applied independent of the deployment, making the deployment less likely to fail. - The effects can be more closely monitored.
1 parent 3d93291 commit 74c8ee0

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

db/migrate/20250506133833_normalise_whitespace.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
desc "Normalise the white space in a number of fields for patients and parents to ensure consistency."
4+
task normalise_whitespace: :environment do
5+
Patient.find_each do |patient|
6+
patient_fields = %i[
7+
given_name
8+
family_name
9+
preferred_given_name
10+
preferred_family_name
11+
address_line_1
12+
address_line_2
13+
address_town
14+
registration
15+
]
16+
17+
patient_fields.each do |field|
18+
patient[field] = patient[field]&.normalise_whitespace
19+
end
20+
21+
Patient.record_timestamps = false
22+
patient.save!
23+
Patient.record_timestamps = true
24+
end
25+
26+
Parent.find_each do |parent|
27+
parent.full_name = parent.full_name&.normalise_whitespace
28+
29+
Parent.record_timestamps = false
30+
parent.save!
31+
Parent.record_timestamps = true
32+
end
33+
end

0 commit comments

Comments
 (0)