From 948f5c0140393164e63afb978e367e7f11772f77 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:15:59 -0300 Subject: [PATCH] DEV: add rake task to annotate plugins in clean DB (#29378) --- lib/tasks/annotate.rake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/tasks/annotate.rake b/lib/tasks/annotate.rake index 56551659d88..7a45699d34d 100644 --- a/lib/tasks/annotate.rake +++ b/lib/tasks/annotate.rake @@ -39,3 +39,23 @@ ensure db&.stop db&.remove end + +desc "regenerate plugin model annotations using a temporary database" +task "annotate:clean:plugins", [:plugin] => :environment do |task, args| + specific_plugin = "--model-dir plugins/#{args[:plugin]}/app/models" if args[:plugin].present? + + db = TemporaryDb.new + db.start + db.with_env do + system("RAILS_ENV=test LOAD_PLUGINS=1 bin/rake db:migrate", exception: true) + system("RAILS_ENV=test LOAD_PLUGINS=1 bin/rake annotate:ensure_all_indexes", exception: true) + system( + "RAILS_ENV=test LOAD_PLUGINS=1 bin/annotate --models #{specific_plugin}", + exception: true, + ) + end + STDERR.puts "Annotate executed successfully" +ensure + db&.stop + db&.remove +end