There isn’t a better task for that, and I don’t know of any included tasks that wait. You could write your own. It would probably look something like
namespace :db do
task wait_for_pending_migrations: :load_config do
pending_migrations = proc do
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).flat_map do |db_config|
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Base.connection.migration_context.open.pending_migrations
end
end
while pending_migrations.call.any?
# maybe you put a counter here to avoid this running forever
sleep(0.5)
end
end
end