diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 08b59df06..520190c88 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -26,6 +26,7 @@ # last_commentaire_updated_at :datetime # motivation :text # private_search_terms :text +# for_procedure_preview :boolean # processed_at :datetime # search_terms :text # state :string @@ -205,13 +206,14 @@ class Dossier < ApplicationRecord scope :not_archived, -> { where(archived: false) } scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) } scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) } - scope :visible_by_user, -> { where(hidden_by_user_at: nil) } + scope :visible_by_user, -> { where(for_procedure_preview: false).or(where(for_procedure_preview: nil)).where(hidden_by_user_at: nil) } scope :visible_by_administration, -> { state_not_brouillon .where(hidden_by_administration_at: nil) .merge(visible_by_user.or(state_not_en_construction)) } scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) } + scope :for_procedure_preview, -> { where(for_procedure_preview: true) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) } diff --git a/db/migrate/20220315124100_add_preview_to_dossiers.rb b/db/migrate/20220315124100_add_preview_to_dossiers.rb new file mode 100644 index 000000000..cff3ee065 --- /dev/null +++ b/db/migrate/20220315124100_add_preview_to_dossiers.rb @@ -0,0 +1,6 @@ +class AddPreviewToDossiers < ActiveRecord::Migration[6.1] + def change + add_column :dossiers, :for_procedure_preview, :boolean + change_column_default :dossiers, :for_procedure_preview, false + end +end diff --git a/db/schema.rb b/db/schema.rb index 63fc7466c..f28167ade 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_04_25_140107) do +ActiveRecord::Schema.define(version: 2022_04_26_140107) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -314,6 +314,7 @@ ActiveRecord::Schema.define(version: 2022_04_25_140107) do t.datetime "en_construction_close_to_expiration_notice_sent_at" t.interval "en_construction_conservation_extension", default: "PT0S" t.datetime "en_instruction_at" + t.boolean "for_procedure_preview", default: false t.bigint "groupe_instructeur_id" t.datetime "groupe_instructeur_updated_at" t.datetime "hidden_at" diff --git a/lib/tasks/deployment/20220427195148_set_default_for_procedure_preview_on_dossiers.rake b/lib/tasks/deployment/20220427195148_set_default_for_procedure_preview_on_dossiers.rake new file mode 100644 index 000000000..d43bcd5da --- /dev/null +++ b/lib/tasks/deployment/20220427195148_set_default_for_procedure_preview_on_dossiers.rake @@ -0,0 +1,16 @@ +namespace :after_party do + desc 'Deployment task: set_default_for_procedure_preview_on_dossiers' + task set_default_for_procedure_preview_on_dossiers: :environment do + puts "Running deploy task 'set_default_for_procedure_preview_on_dossiers'" + + Dossier + .where(for_procedure_preview: nil) + .in_batches(of: 5_000) + .update_all(for_procedure_preview: false) + + # 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