Skip to content

Commit

Permalink
FIX shard_names returns duplicate shard names
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbhatt committed Sep 15, 2023
1 parent 9c974ca commit 726c2e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Expand Up @@ -8,7 +8,7 @@ def initialize
end

def shard_names
@role_to_shard_mapping.values.flat_map { |shard_map| shard_map.keys }
@role_to_shard_mapping.values.flat_map { |shard_map| shard_map.keys }.uniq
end

def role_names
Expand Down
Expand Up @@ -38,13 +38,14 @@ def test_establish_connection_using_3_levels_config
@prev_configs, ActiveRecord::Base.configurations = ActiveRecord::Base.configurations, config

ActiveRecord::Base.connects_to(shards: {
default: { writing: :primary },
shard_one: { writing: :primary_shard_one }
default: { writing: :primary, reading: :primary },
shard_one: { writing: :primary_shard_one, reading: :primary_shard_one }
})

base_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool("ActiveRecord::Base")
default_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool("ActiveRecord::Base", shard: :default)

assert_equal [:default, :shard_one], ActiveRecord::Base.connection_handler.send(:get_pool_manager, "ActiveRecord::Base").shard_names
assert_equal base_pool, default_pool
assert_equal "test/db/primary.sqlite3", default_pool.db_config.database
assert_equal "primary", default_pool.db_config.name
Expand Down

0 comments on commit 726c2e4

Please sign in to comment.