Merge pull request #10617 from tchak/fix-non-unique-champs

chore(champs): task to move non unique champs to a bad_data stream
This commit is contained in:
Paul Chavard 2024-07-16 12:25:41 +00:00 committed by GitHub
commit 0b6fefa582
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,21 @@
module Maintenance
class RemoveNonUniqueChampsTask < MaintenanceTasks::Task
attribute :stable_ids, :string
validates :stable_ids, presence: true
def collection
champs = Champ.where(stable_id: stable_ids.split(',').map(&:strip).map(&:to_i))
champs
.group_by { [_1.dossier_id, _1.stream, _1.stable_id, _1.row_id] }
.values
.filter { _1.size > 1 }
end
def process(champs)
champs_to_remove = champs.sort_by(&:updated_at)[0...-1]
champs_to_remove.each do |champ|
champ.update_column(:stream, 'bad_data')
end
end
end
end