2021-05-05 21:05:33 +02:00
|
|
|
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
|
2021-05-05 21:05:33 +02:00
|
|
|
|
2022-01-28 13:03:57 +01:00
|
|
|
ignored_columns = Dossier.ignored_columns.dup
|
|
|
|
Dossier.ignored_columns -= ["en_construction_conservation_extension"]
|
|
|
|
|
2021-05-05 21:05:33 +02:00
|
|
|
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
|
2021-05-05 21:05:33 +02:00
|
|
|
end
|
2021-05-06 16:25:34 +02:00
|
|
|
progress.finish
|
2021-05-05 21:05:33 +02:00
|
|
|
|
2022-01-28 13:03:57 +01:00
|
|
|
Dossier.ignored_columns = ignored_columns
|
|
|
|
|
2021-05-06 12:49:37 +02:00
|
|
|
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
|
2021-05-05 21:05:33 +02:00
|
|
|
end
|
2021-05-06 16:25:34 +02:00
|
|
|
progress.finish
|
2021-05-05 21:05:33 +02:00
|
|
|
|
|
|
|
# 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
|