Merge pull request #10155 from demarches-simplifiees/tchak-patch-1

task(champs): update champs for each dossier
This commit is contained in:
Colin Darie 2024-03-19 15:29:37 +00:00 committed by GitHub
commit 0977bd39d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,18 +3,16 @@
module Maintenance
class FillChampsStableIdTask < MaintenanceTasks::Task
def collection
Champ.all
Dossier.all
end
def process(champ)
if !champ.attribute_present?(:stable_id)
champ.update_columns(stable_id: champ.stable_id, stream: 'main')
end
end
def count
sql = "SELECT reltuples FROM pg_class WHERE relname = 'champs';"
Champ.connection.select_value(sql).to_i
def process(dossier)
dossier.champs
.includes(:type_de_champ)
.where(stable_id: nil)
.find_each do |champ|
champ.update_columns(stable_id: champ.stable_id, stream: 'main')
end
end
end
end