Skip to content

A platform for community discussion. Free, open, simple.

DEV: add rake task to annotate plugins in clean DB (#29378)

Gabriel Grubba948f5c014039
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