Revert "migration: normalize regions (#8521)"
This reverts commit 8fee658eba
.
This commit is contained in:
parent
2db37327fb
commit
db36397bc5
2 changed files with 0 additions and 184 deletions
|
@ -1,45 +0,0 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: normalize_regions'
|
||||
task normalize_regions: :environment do
|
||||
puts "Running deploy task 'normalize_regions'"
|
||||
|
||||
scope_external_id_blank_value_blank = Champs::RegionChamp.where(external_id: [nil, ''], value: [nil, ''])
|
||||
scope_value_blank = Champs::RegionChamp.where(value: [nil, '']).where.not(external_id: [nil, ''])
|
||||
scope_external_id_blank = Champs::RegionChamp.where(external_id: [nil, '']).where.not(value: [nil, ''])
|
||||
scope_provence = Champs::RegionChamp.where(value: "Provence-Alpes-Côte d'Azur")
|
||||
|
||||
progress = ProgressReport.new(
|
||||
scope_external_id_blank_value_blank.count +
|
||||
scope_value_blank.count +
|
||||
scope_external_id_blank.count +
|
||||
scope_provence.count
|
||||
)
|
||||
|
||||
scope_external_id_blank_value_blank.in_batches(of: 10_000) do |regions|
|
||||
progress.inc(regions.count)
|
||||
regions.update_all(external_id: nil, value: nil)
|
||||
end
|
||||
|
||||
scope_value_blank.find_each do |champ|
|
||||
champ.update_columns(value: APIGeoService.region_name(champ.external_id))
|
||||
progress.inc
|
||||
end
|
||||
|
||||
scope_external_id_blank.find_each do |champ|
|
||||
champ.update_columns(external_id: APIGeoService.region_code(champ.value))
|
||||
progress.inc
|
||||
end
|
||||
|
||||
scope_provence.in_batches(of: 10_000) do |regions|
|
||||
progress.inc(regions.count)
|
||||
regions.update_all(external_id: "93", value: "Provence-Alpes-Côte d’Azur")
|
||||
end
|
||||
|
||||
progress.finish
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord
|
||||
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue