0d41bfd3cc
If an application is using sharding, they may not want to use `default` as the `default_shard`. Unfortunately Rails expects there to be a shard named `default` for certain actions internally. This leads to some errors on boot and the application is left manually setting `default_shard=` in their model or updating their shards in `connects_to` to name `shard_one` to `default`. Neither are a great solution, especially if Rails can do this for you. Changes to Active Record are: * Simplify `connects_to` by merging `database` into `shards` kwarg so we can do a single loop through provided options. * Set the `self.default_shard` to the first keys in the shards kwarg. * Add a test for this behavior * Update existing test that wasn't testing this to use `default`. I could have left this test but it really messes with connections in the other tests and since this isn't testing shard behavior specifically, I updated it to use `default` as the default shard name. This is a slight change in behavior from existing applications but arguably this is fixing a bug because without this an application won't boot. I originally thought that this would require a huge refactoring to fix but realized that it makes a lot of sense to take the first shard as they default. They should all have the same schema so we can assume it's fine to take the first one. Fixes: #45390 |
||
---|---|---|
.. | ||
active_record | ||
arel | ||
rails/generators | ||
active_record.rb | ||
arel.rb |