Skip to content

Commit

Permalink
feat(champ): migrate champ expression reguliere type to formatted
Browse files Browse the repository at this point in the history
Co-Authored-By: Christophe Robillard <christophe.robillard@mail.numerique.gouv.fr>
Co-Authored-By: simon lehericey <mail@simon.lehericey.net>
  • Loading branch information
3 people committed Dec 4, 2024
1 parent 3ba79f6 commit 2427d31
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module Maintenance
class T20241127MigrateChampExpressionReguliereToFormattedTask < MaintenanceTasks::Task
# Documentation: les champs ExpressionReguliere sont migrés au nouveau champ Formatted
# en mode avancé.
# Voir aussi la maintenance task de transformation des types de champs.

include RunnableOnDeployConcern
include StatementsHelpersConcern

# Uncomment only if this task MUST run imperatively on its first deployment.
# If possible, leave commented for manual execution later.
run_on_first_deploy

def collection
with_statement_timeout("5min") do
Champ.where(type: ["Champs::ExpressionReguliereChamp", "Champs::FormattedChamp"]).in_batches
end
end

def process(batch)
batch.update_all(type: "Champs::FormattedChamp")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

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

def collection
TypeDeChamp.where(type_champ: 'expression_reguliere')
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require "rails_helper"

module Maintenance
RSpec.describe T20241127MigrateChampExpressionReguliereToFormattedTask do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: "expression_reguliere" }, { type: "text" }]) }
let(:dossier) { create(:dossier, :with_populated_champs, procedure: procedure) }

describe "#process" do
let(:batch_of_champs) { Champ.where(type: ["Champs::ExpressionReguliereChamp", "Champs::FormattedChamp"]).in_batches }
subject(:process) { described_class.process(batch_of_champs) }

it "works" do
dossier
process
expect(Champ.first.type).to eq("Champs::FormattedChamp")
end
end

describe '#collection' do
it "works" do
dossier # create dossier
expect(described_class.collection.relation.map(&:type)).to eq(["Champs::ExpressionReguliereChamp"])
end
end
end
end

0 comments on commit 2427d31

Please sign in to comment.