Merge pull request #6175 from tchak/add_brouillon_extend_conservation_column

Rename en_construction_conservation_extension to conservation_extension
This commit is contained in:
Paul Chavard 2021-05-11 14:17:47 +02:00 committed by GitHub
commit a5d217aec2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 2 deletions

View file

@ -161,7 +161,8 @@ module Users
end
def extend_conservation
dossier.update(en_construction_conservation_extension: dossier.en_construction_conservation_extension + 1.month)
dossier.update(en_construction_conservation_extension: dossier.en_construction_conservation_extension + 1.month,
conservation_extension: dossier.en_construction_conservation_extension + 1.month)
flash[:notice] = 'Votre dossier sera conservé un mois supplémentaire'
redirect_to dossier_path(@dossier)
end

View file

@ -7,6 +7,7 @@
# archived :boolean default(FALSE)
# autorisation_donnees :boolean
# brouillon_close_to_expiration_notice_sent_at :datetime
# conservation_extension :interval default(0 seconds)
# deleted_user_email_never_send :string
# en_construction_at :datetime
# en_construction_close_to_expiration_notice_sent_at :datetime
@ -636,6 +637,7 @@ class Dossier < ApplicationRecord
end
def after_passer_en_construction
update!(conservation_extension: 0.days)
update!(en_construction_at: Time.zone.now) if self.en_construction_at.nil?
end
@ -652,6 +654,7 @@ class Dossier < ApplicationRecord
end
def after_repasser_en_construction(instructeur)
update!(conservation_extension: 0.days)
log_dossier_operation(instructeur, :repasser_en_construction)
end

View file

@ -0,0 +1,5 @@
class AddConservationExtensionToDossiers < ActiveRecord::Migration[6.1]
def change
add_column :dossiers, :conservation_extension, :interval
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_05_04_115445) do
ActiveRecord::Schema.define(version: 2021_05_05_115445) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -274,6 +274,7 @@ ActiveRecord::Schema.define(version: 2021_05_04_115445) do
t.datetime "last_avis_updated_at"
t.datetime "last_commentaire_updated_at"
t.string "api_entreprise_job_exceptions", array: true
t.interval "conservation_extension"
t.string "deleted_user_email_never_send"
t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin
t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin

View file

@ -0,0 +1,29 @@
namespace :after_party do
desc 'Deployment task: rename_conservation_extension'
task rename_conservation_extension: :environment do
puts "Running deploy task 'rename_conservation_extension'"
BATCH_SIZE = 20_000
dossiers = Dossier.state_en_construction.where.not(en_construction_conservation_extension: 0.days)
progress = ProgressReport.new((dossiers.count.to_f / BATCH_SIZE).round)
dossiers.in_batches(of: BATCH_SIZE) do |relation|
relation.update_all("dossiers.conservation_extension = dossiers.en_construction_conservation_extension")
progress.inc
end
progress.finish
dossiers_without_conservation_extension = Dossier.where(conservation_extension: nil)
progress = ProgressReport.new((dossiers_without_conservation_extension.count.to_f / BATCH_SIZE).round)
dossiers_without_conservation_extension.in_batches(of: BATCH_SIZE) do |relation|
relation.update_all(conservation_extension: 0.days)
progress.inc
end
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