{"id":18656566,"url":"https://github.com/zendesk/active_record_host_pool","last_synced_at":"2025-04-07T08:29:00.865Z","repository":{"id":553433,"uuid":"1577990","full_name":"zendesk/active_record_host_pool","owner":"zendesk","description":"Connect to multiple databases using one ActiveRecord connection","archived":false,"fork":false,"pushed_at":"2025-02-03T20:46:29.000Z","size":563,"stargazers_count":16,"open_issues_count":3,"forks_count":6,"subscribers_count":414,"default_branch":"main","last_synced_at":"2025-03-31T07:06:58.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zendesk.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-04-06T16:18:31.000Z","updated_at":"2025-03-29T21:03:29.000Z","dependencies_parsed_at":"2024-04-02T08:28:42.728Z","dependency_job_id":"cd9ef033-a5c3-4996-a113-4111b2e85b6e","html_url":"https://github.com/zendesk/active_record_host_pool","commit_stats":{"total_commits":340,"total_committers":27,"mean_commits":"12.592592592592593","dds":0.7205882352941176,"last_synced_commit":"ba9768e62aca6ad89491d4d440a10a91da5ba8a6"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_host_pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_host_pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_host_pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_host_pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zendesk","download_url":"https://codeload.github.com/zendesk/active_record_host_pool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247618536,"owners_count":20967798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T07:24:03.784Z","updated_at":"2025-04-07T08:29:00.839Z","avatar_url":"https://github.com/zendesk.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/zendesk/active_record_host_pool/workflows/CI/badge.svg)](https://github.com/zendesk/active_record_host_pool/actions?query=workflow%3ACI)\n\n# ActiveRecord host pooling\n\nThis gem allows for one ActiveRecord connection to be used to connect to multiple databases on a server.\nIt accomplishes this by calling select_db() as necessary to switch databases between database calls.\n\n## How Connections Are Pooled\n\nARHP creates separate connection pools based on the pool key.\n\nThe pool key is defined as:\n\n`host / port / socket / username / replica`\n\nTherefore two databases with identical host, port, socket, username, and replica status will share a connection pool.\nIf any part (host, port, etc.) of the pool key differ, two databases will _not_ share a connection pool.\n\n`replica` in the pool key is a boolean indicating if the database is a replica/reader (true) or writer database (false).\n\nBelow, `test_pool_1` and `test_pool_2` have identical host, username, socket, and replica status but the port information differs.\nHere the database configurations are formatted as a table to give a visual example:\n\n|          |  test_pool_1   |  test_pool_2   |\n|----------|----------------|----------------|\n| host     | 127.0.0.1      | 127.0.0.1      |\n| port     |                | 3306           |\n| socket   |                |                |\n| username | root           | root           |\n| replica  | false          | false          |\n\nThe configuration items must be explicitly defined or they will be blank in the pool key.\nConfigurations with matching _implicit_ items but differing _explicit_ items will create separate pools.\ne.g. `test_pool_1` will default to port 3306 but because it is not explicitly defined it will not share a pool with `test_pool_2`\n\nARHP will therefore create the following pool keys:\n\n```\ntest_pool_1 =\u003e 127.0.0.1///root/false\ntest_pool_2 =\u003e 127.0.0.1/3306//root/false\n```\n\n\n## Support\n\nFor now, the only backend known to work is MySQL, with the mysql2 or activerecord-trilogy-adapter gem. When using the activerecord-trilogy-adapter ensure that the transitive dependency Trilogy is v2.5.0+.\nPostgres, from an informal reading of the docs, will never support the concept of one server connection sharing multiple dbs.\n\n## Installation\n\n    $ gem install active_record_host_pool\n\nand make sure to require 'active\\_record\\_host\\_pool' in some way.\n\n## Testing\nYou need a local user called 'john-doe'.\n\n    mysql -uroot\n    CREATE USER 'john-doe'@'localhost';\n    GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX  ON *.* TO 'john-doe'@'localhost';\n    FLUSH PRIVILEGES;\n\nWith mysql running locally, run\n\n    BUNDLE_GEMFILE=gemfiles/rails6.1.gemfile bundle exec rake test\n\n Or\n\n    BUNDLE_GEMFILE=gemfiles/rails6.1.gemfile ruby test/test_arhp.rb --seed 19911 --verbose\n\n## Copyright\n\nCopyright (c) 2011 Zendesk. See MIT-LICENSE for details.\n\n## Authors\nBen Osheroff \u003cben@gimbo.net\u003e,\nMick Staugaard \u003cmick@staugaard.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Factive_record_host_pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzendesk%2Factive_record_host_pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Factive_record_host_pool/lists"}