data(backfill): Champs::SiretChamp.value_json [±1.4M occurences]
This commit is contained in:
parent
917f25dcfd
commit
a66bd46082
2 changed files with 49 additions and 0 deletions
18
app/tasks/maintenance/populate_siret_value_json_task.rb
Normal file
18
app/tasks/maintenance/populate_siret_value_json_task.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Maintenance
|
||||||
|
class PopulateSiretValueJSONTask < MaintenanceTasks::Task
|
||||||
|
def collection
|
||||||
|
Champs::SiretChamp.where.not(value: nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
def process(champ)
|
||||||
|
return if champ.etablissement.blank?
|
||||||
|
champ.update!(value_json: APIGeoService.parse_etablissement_address(champ.etablissement))
|
||||||
|
end
|
||||||
|
|
||||||
|
def count
|
||||||
|
# not really interested in counting because it raises PG Statement timeout
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
module Maintenance
|
||||||
|
RSpec.describe PopulateSiretValueJSONTask do
|
||||||
|
describe "#process" do
|
||||||
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
|
||||||
|
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
||||||
|
let(:element) { dossier.champs.first }
|
||||||
|
subject(:process) { described_class.process(element) }
|
||||||
|
|
||||||
|
it 'updates value_json' do
|
||||||
|
expect { subject }.to change { element.reload.value_json }
|
||||||
|
.from(nil)
|
||||||
|
.to({
|
||||||
|
"city_code" => "92009",
|
||||||
|
"city_name" => "Bois-Colombes",
|
||||||
|
"postal_code" => "92270",
|
||||||
|
"region_code" => "11",
|
||||||
|
"region_name" => "Île-de-France",
|
||||||
|
"street_name" => "RAOUL NORDLING",
|
||||||
|
"street_number" => "6",
|
||||||
|
"street_address" => "6 RUE RAOUL NORDLING",
|
||||||
|
"departement_code" => "92",
|
||||||
|
"departement_name" => "Hauts-de-Seine"
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue