demarches-normaliennes/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake

35 lines
1.4 KiB
Ruby
Raw Normal View History

namespace :after_party do
desc 'Deployment task: rename_conservation_extension'
task rename_conservation_extension: :environment do
puts "Running deploy task 'rename_conservation_extension'"
2021-05-06 16:25:34 +02:00
BATCH_SIZE = 20_000
ignored_columns = Dossier.ignored_columns.dup
Dossier.ignored_columns -= ["en_construction_conservation_extension"]
dossiers = Dossier.state_en_construction.where.not(en_construction_conservation_extension: 0.days)
2021-05-06 16:25:34 +02:00
progress = ProgressReport.new((dossiers.count.to_f / BATCH_SIZE).round)
dossiers.in_batches(of: BATCH_SIZE) do |relation|
2021-05-11 14:53:41 +02:00
relation.update_all("conservation_extension = en_construction_conservation_extension")
2021-05-06 16:25:34 +02:00
progress.inc
end
2021-05-06 16:25:34 +02:00
progress.finish
Dossier.ignored_columns = ignored_columns # rubocop:disable Rails/IgnoredColumnsAssignment
dossiers_without_conservation_extension = Dossier.where(conservation_extension: nil)
2021-05-06 16:25:34 +02:00
progress = ProgressReport.new((dossiers_without_conservation_extension.count.to_f / BATCH_SIZE).round)
dossiers_without_conservation_extension.in_batches(of: BATCH_SIZE) do |relation|
2021-05-11 15:29:41 +02:00
relation.update_all(conservation_extension: 'PT0S')
2021-05-06 16:25:34 +02:00
progress.inc
end
2021-05-06 16:25:34 +02:00
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end