From f199cb1bea6a22566056db1d58cd7edc23806bcb Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 6 Mar 2020 17:45:03 +0100 Subject: [PATCH] Warn but allow executing :truncate_data in prod --- lib/tasks/data/truncate_data.rake | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/tasks/data/truncate_data.rake b/lib/tasks/data/truncate_data.rake index 12c7866926..c1c94b7310 100644 --- a/lib/tasks/data/truncate_data.rake +++ b/lib/tasks/data/truncate_data.rake @@ -10,20 +10,18 @@ namespace :ofn do namespace :data do desc 'Truncate data' task :truncate, [:months_to_keep] => :environment do |_task, args| - guard_and_warn + warn_with_confirmation months_to_keep = args.months_to_keep.to_i TruncateData.new(months_to_keep).call end - def guard_and_warn - if Rails.env.production? - Rails.logger.info("This task cannot be executed in production") - exit - end - - message = "\n <%= color('This will permanently change DB contents', :yellow) %>, - are you sure you want to proceed? (y/N)" + def warn_with_confirmation + message = <<-MSG.strip_heredoc + \n + <%= color('This will permanently change DB contents. Please, make a backup first.', :yellow) %> + Are you sure you want to proceed? (y/N) + MSG exit unless HighLine.new.agree(message) { |q| q.default = "n" } end end