demarches-normaliennes/app/tasks/maintenance/fill_champs_stable_id_task.rb

24 lines
673 B
Ruby
Raw Normal View History

2024-03-15 14:56:46 +01:00
# frozen_string_literal: true
module Maintenance
class FillChampsStableIdTask < MaintenanceTasks::Task
BATCH = 20
2024-03-28 17:35:17 +01:00
2024-03-15 14:56:46 +01:00
def collection
2024-03-28 17:35:17 +01:00
(Dossier.last.id / BATCH).ceil.times.to_a
2024-03-15 14:56:46 +01:00
end
2024-03-28 17:35:17 +01:00
def process(batch_number)
dossier_id_start = batch_number * BATCH
dossier_id_end = dossier_id_start + BATCH
Champ
.where(dossier_id: dossier_id_start..dossier_id_end, stable_id: nil)
.joins(:type_de_champ)
.select('champs.id, types_de_champ.stable_id as type_de_champ_stable_id')
2024-03-19 16:20:24 +01:00
.find_each do |champ|
2024-03-28 17:35:17 +01:00
champ.update_columns(stable_id: champ.type_de_champ_stable_id, stream: 'main')
end
end
2024-03-15 14:56:46 +01:00
end
end