Skip to content

Commit 28ae615

Browse files
Add migration to backfill the district_name field for US schools wher… (#661)
## Status - [Closes](RaspberryPiFoundation/digital-editor-issues#1092) ## What's changed? - Add migration to backfill the `district_name` field on schools where the `country_code` is US and `district_name` is null or empty
1 parent b2ab5f7 commit 28ae615

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class BackfillDistrictNameForUsSchools < ActiveRecord::Migration[7.2]
2+
def up
3+
School
4+
.where(country_code: "US")
5+
.where("district_name IS NULL OR BTRIM(district_name) = ''")
6+
.update_all(district_name: "District Unknown")
7+
end
8+
9+
def down
10+
School
11+
.where(country_code: "US")
12+
.where(district_name: "District Unknown")
13+
.update_all(district_name: nil)
14+
end
15+
end

db/schema.rb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)