2024-03-15 14:56:46 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Maintenance
|
|
|
|
class FillChampsStableIdTask < MaintenanceTasks::Task
|
2024-04-02 15:55:44 +02:00
|
|
|
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')
|
2024-03-19 16:08:56 +01:00
|
|
|
end
|
2024-03-18 17:06:24 +01:00
|
|
|
end
|
2024-03-15 14:56:46 +01:00
|
|
|
end
|
|
|
|
end
|