Skip to content

Commit

Permalink
backfill address champ value_json
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim committed Jan 14, 2025
1 parent d3c99d0 commit ef2ba2b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/tasks/maintenance/backfill_address_value_json_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Maintenance
class BackfillAddressValueJSONTask < MaintenanceTasks::Task
include RunnableOnDeployConcern
include StatementsHelpersConcern

no_collection

def process
sql = "UPDATE champs SET value_json = data WHERE type = 'Champs::AddressChamp' AND data IS NOT NULL;"

with_statement_timeout("5min") do
Champ.connection.execute(sql)
end
end
end
end
27 changes: 27 additions & 0 deletions spec/tasks/maintenance/backfill_address_value_json_task_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "rails_helper"

module Maintenance
RSpec.describe BackfillAddressValueJSONTask do
describe "#process" do
subject(:process) { described_class.process }

let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :address, libelle: 'address' }]) }
let(:dossier) { create(:dossier, procedure:) }
let(:address_champ) { dossier.project_champs_public.first }
let(:address_data) { { 'address' => 'address' } }

before { address_champ.update(data: address_data) }

it do
expect(address_champ.value_json).to be_nil

process
address_champ.reload

expect(address_champ.value_json).to eq(address_data)
end
end
end
end

0 comments on commit ef2ba2b

Please sign in to comment.