With native horizontal sharding in place, an API to be able to run snippets across all shards for a given
ActiveRecord::Base abstract class(
ApplicationRecord in most cases) would be a definite nice to have.
def run_something_on_all_shards ApplicationRecord.shards.each do |shard| ApplicationRecord.connected_to(shard: shard, role: :writing) do # execute some script for data collection / updation. end end end
The alternative to this would be to provide a hook to execute a block of code on all connections, but I felt like that’s application logic.
def run_something_on_all_shards ApplicationRecord.on_all_shards(role: :writing).each do |shard| # execute some script for data collection / updation. end end
This is a regular use-case for running 1-off scripts across all your tenants. Keeping/reading shard information across multiple PODs for every run isn’t practical.
Happy to help with a PR based on suggestions.